Opened 16 years ago

Closed 16 years ago

#9629 closed (invalid)

DateField / DateTimeField issues in admin site when using auto_now in field model

Reported by: ctieche Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords: Date
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a DateField or DateTimeField is included in a model, and the auto_now=True or auto_now_add=True option is used, the following message is issued by django when attempting to access the Admin site with that date or datetime. Note that the field must be referenced in a field_sets list:

ImproperlyConfigured: 'MyAdmin.fieldsets[3][1]fields' refers to field 'changedwhen' that is missing from the form.

Removing the auto_now option resolves the problem.
If field_sets are not used, the error does not occur, but the date(time) field does not appear on the default admin site. Again, removing the auto_now option solves the problem and the field appears in the auto generated admin site as expected.

Change History (2)

comment:1 by Ramiro Morales, 16 years ago

Using auto_now or auto_now_add set internally editable to False because then the {Date,}TimeField where you've used them isn't supposed to be editable by the user but handled by Django, furthermore as Django forms currently don't have the concept of immutable fields (visible in a form but non-modifiable) this means that you can't use the field name in question in the display-related Admin options for the model without getting the error you are seeing.

comment:2 by Karen Tracey, 16 years ago

Resolution: invalid
Status: newclosed

So this may get improved as a side-effect of adding read-only fields, but for now it's working as designed and it doesn't need it's own ticket. In the meantime there are workarounds, see this thread:

http://groups.google.com/group/django-developers/browse_thread/thread/4cd631c225cb4e52/be97856ca67ede3f?

from when removing these options entirely was discussed (not sure why that didn't actually happen).

Note: See TracTickets for help on using tickets.
Back to Top