Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda