Best way to implement date with optional day/month?
There are several ways to do this, each with their own advantages and disadvantages.
- Boolean fields for day/month:
- Advantages: cheap ordering, easy formatting, easy validation
- Disadvantages: have to provide a default month/day, ordering may not behave as expected depending on needs
date = models.DateField()
date_has_month = models.BooleanField()
date_has_day = models.BooleanField()
- Separate IntegerFields
- Advantages: relatively cheap ordering, flexible ordering with not_null option etc
- Disadvantages: complicates date validation, must order on several fields, must compose date from several fields
date_year = models.IntegerField()
date_month = models.IntegerField()
date_day = models.IntegerField()
- CharField
- Advantages: no need for extra fields, 1:1 with user input (depending on validation)
- Disadvantages: relatively expensive ordering, ordering is inflexible, validation may be complicated
date = models.CharField()
My question is: are there more (dis)advantages not listed? Are there other ways to achieve this that I haven't thought of?