#7993 closed Uncategorized (invalid)
Admin complains about a missing field even if it is not missing
Reported by: | Ivan Giuliani | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | admin, improperlyconfigured |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django raises an ImproperlyConfigured
exception (NewsAdmin.fieldsets[1][1]['fields']
refers to field `pub_date`
that is missing from the form) when the following admin interface is defined:
class NewsAdmin(admin.ModelAdmin): fieldsets = ( (None, { 'fields': ('title', 'text'), }), (_('Other stuff'), { 'fields': ('language', 'pub_date'), }), )
But the model has a pub_date field:
class News(models.Model): title = models.CharField(max_length=50) pub_date = models.DateTimeField(auto_now=True, blank=True) text = models.TextField() language = models.ForeignKey(LanguageRef) def save(self): if not self.pub_date: self.pub_date = datetime.datetime.now() super(News, self).save() class Meta: get_latest_by = "pub_date" verbose_name = "news" verbose_name_plural = "news"
If I remove pub_date
from the fields
attribute in the NewsAdmin
everything works as expected.
Change History (6)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 15 years ago
That would be still useful to be able to display the field in the admin. Maybe in a disabled input, ie: <input disabled />
comment:3 by , 15 years ago
Replying to batiste:
That would be still useful to be able to display the field in the admin. Maybe in a disabled input, ie: <input disabled />
This is possible now (new in 1.2) with readonly fields in the admin, though it does not actually used disabled inputs.
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
For others who may run into this symptom for unrelated reasons, try restarting your server.
comment:6 by , 11 years ago
Replying to mwaigaryan@…:
same problem in Django-1.4.2,is there a patch?
As above, put it in the readonly_fields list in the model admin, then it displays fine
I suspect you get the error because auto_now=True is specified for this field. That makes it a non-editable field, since the value is not something the user can change, see http://www.djangoproject.com/documentation/model-api/#datefield:
"Note that the current date is always used; it’s not just a default value that you can override."
Since it's not editable there's no point in putting it in the form.