Reputation: 257
I try to display a modelform containing a datetime field.
But when I try to display this field, nothing appears.
In the model form, when I print self.fields :
{'status': <django.forms.fields.TypedChoiceField object at 0x1340e10>, 'reserved': <django.forms.fields.BooleanField object at 0x1340cd0>, 'date_publication': None, 'date_creation': None}
Here's the model :
class News(MultiLangModel):
date_creation = models.DateTimeField(auto_now_add=True, verbose_name=_("Date"))
date_publication = models.DateTimeField(auto_now_add=True, verbose_name=_("Publication date"))
status = models.CharField(max_length=10, verbose_name=_("Status"), choices=POST_STATUS_CHOICES)
reserved = models.BooleanField(default=False, verbose_name=_(u"News reserved to supporters"))
What can be the reason of this bug ?
Upvotes: 1
Views: 1315
Reputation: 74675
You have set the auto_now_add
attribute to True
for date_publication
. This implies that the value of this field will be set automatically and not from user input. To verify this remove the auto_now_add
attribute and try again.
From the docs for auto_now_add
:
Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it's not just a default value that you can override.
Upvotes: 3