Administrator models do not recognize inherited fields

I am wondering if this is something special for django.admin, django or even python? But I do not really understand the meaning of having abstract superclasses if I cannot access their fields :-). Did I do something wrong?

Example: I get a FieldError with the following value "Exceptional value: unknown fields (create_date) specified for the module.) Check the fields / fields / exclude the attributes of the ModuleAdmin class" if I use the admin interface to get the following module model:

class GeneralModel(models.Model): creation_date = models.DateTimeField('date of creation', auto_now_add=True) edited_date = models.DateTimeField('date of last modification', auto_now=True) class Meta: abstract = True class Module(GeneralModel): name = models.CharField(max_length=100) shortDescription = models.CharField("summary", max_length=100) description = models.CharField("description", max_length=1500) authors = models.ManyToManyField("Author", through="Authorship") def __unicode__(self): return self.name 

With the following ModelAdmin code:

 class ModuleAdmin(admin.ModelAdmin): def formfield_for_dbfield(self, db_field, **kwargs): formfield = super(ModuleAdmin, self).formfield_for_dbfield(db_field, **kwargs) if db_field.name == 'description': formfield.widget = forms.Textarea(attrs=formfield.widget.attrs) return formfield fieldsets = [ ("General", {"fields": ["name", "shortDescription"]}), ("Details", {"fields": ["description", "creation_date"], "classes": ["collapse"]}) ] 
+8
django django-admin
source share
1 answer

Your problem is related to the answer: stack overflow

The error is related to the date when auto_now_add = True (or auto_now = True). Since the value is automatic, it is not editable, therefore it is not in the form

According to the documentation:

The fields option ... can contain calls only if they are specified in readonly_fields.

+16
source share

All Articles