Joe*_*nin 5 python django datetime date django-models
我希望Django模型有一个日期字段,其中年,月和日都是可选的.示例值可以是通用的,也可以2008是特定的May 10, 2008.是否可以定义一个DateField这样的行为?或者我最好将年/月/日定义为单独的整数,像这样?
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)
Run Code Online (Sandbox Code Playgroud)
https://github.com/dracos/django-date-extensions上的django-date-extensions (由我完全用于此目的)包括一个ApproximateDate对象,用于处理可能没有月份或日期的日期.