45👍
✅
Your problem is the auto_now_add=True
on that field. See the notes on the documentation for DateField:
Note that the current date is always used; it’s not just a default value that you can override.
and
As currently implemented, setting
auto_now
orauto_now_add
toTrue
will cause the field to haveeditable=False
andblank=True
set.
Since editable=False, you can’t include it in the list of fields for that form (you could put it in readonly_fields
, of course).
If you want the value to take the creation date as a default, but still allow it to be edited and overridden, you should use default
instead:
added_on = models.DateTimeField(default=datetime.datetime.now)
(side note, you should always use the callable for the default value, without the calling parentheses).
Source:stackexchange.com