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 , 16 years ago
comment:2 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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:
from when removing these options entirely was discussed (not sure why that didn't actually happen).
Using
auto_now
orauto_now_add
set internallyeditable
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.