Additional year / month / day in the date field (models) of the Django model

I want the Django model to have a date field in which year, month and day are optional. An approximate value may be general as 2008or as specific as May 10, 2008. Is it possible to define a DateFieldto behave this way? Or is it better for me to define year / month / day as separate integers, for example?

model Book(models.Model):
    publication_year = models.IntegerField(blank=True, null=True)
    publication_month = models.IntegerField(blank=True, null=True)
    publication_day = models.IntegerField(blank=True, null=True)
+5
source share
2 answers

django-date-extensions at https://github.com/dracos/django-date-extensions (for me, just for this purpose) includes an ApproximateDate object to handle dates that may not be a month or a day.

+5
source

Django DateTimeField python datetime.datetime, , :

datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

Django DateTimeField , , .

+2

All Articles