Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Admin and Meta don't see the fields of parent abstract classes

I use Django 1.10. I have the following model structure:

class GenericPage(models.Model):
    """Abstract page, other pages inherit from it."""
    book = models.ForeignKey('Book', on_delete=models.CASCADE)

    class Meta:
        abstract = True

class GenericColorPage(models.Model):
    """Abstract page that is sketchable and colorable, other pages inherit from it."""
    sketched = models.BooleanField(default=False)
    colored = models.BooleanField(default=False)

    class Meta:
        abstract = True

class GenericBookPage(GenericColorPage):
    """A normal book page, with a number. Needs to be storyboarded and edited."""

    ###
    #various additional fields
    ###

    class Meta:
        # unique_together = (('page_number', 'book'),) # impedes movement of pages
        ordering = ('-book', '-page_number',)
        abstract = True

    objects = BookPageManager()  # the manager for book pages

class BookPage(GenericBookPage):
    """Just a regular book page with text (that needs to be proofread)"""
    proofread = models.BooleanField(default=False)

Additionally, an excerpt from Admin:

class BookPageAdmin(admin.ModelAdmin):
    # fields NOT to show in Edit Page.
    list_display = ('__str__', 'page_name', 'sketched', 'colored', 'edited', 'proofread',)
    list_filter = ('book',)
    readonly_fields = ('page_number',)  # valid page number is assigned via overridden save() in model
    actions = ['delete_selected',]

I tried to do ./manage.py makemigrations but if throws the following errors:

<class 'progress.admin.BookPageAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'book', which does not refer to a Field.
progress.BookPage: (models.E015) 'ordering' refers to the non-existent field 'book'.

In the past, when I did not use the abstracts and just put everything into BookPage model, it all worked fine. But it seems that Meta and Admin don't see the fields in parent classes. Am I missing something? Is there a way to make them read fields from abstract parents?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In the past, when I did not use the abstracts and just put everything into BookPage model, it all worked fine

Of course it worked fine because you put everything inside BookPage which is not an abstract class which means that table (and, thus, fields) will be created.

But it seems that Meta and Admin don't see the fields in parent classes. Am I missing something?

You're missing the fact that none of your models inherits from the GenericPage abstract model. Thus, the book field is never created.

Is there a way to make them read fields from abstract parents?

You must create/modify a model that inherits from an abstract model. Maybe, do this:

class GenericBookPage(GenericColorPage, GenericPage):

which allows you to inherit both GenericColorPage and GenericPage fields. When I say inherit I mean when the migrate command runs to actually create the database table and the relevant columns (model fields).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!