Code

Opened 5 years ago

Closed 5 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: UI/UX:

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.

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 5 years ago by kmtracey

  • Resolution set to invalid
  • Status changed from new to 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:

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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.