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

249
Vistas
GenericTabularInline isn't returning what it should in my Django Admin

I have the following models.py file:

class Product(Model):
    ...

class ExtraService(Model):
    ...

class Order(Model):
    ...

class OrderItem(Model):
    order = models.ForeignKey(verbose_name=_('Order Item'), to=Order)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    item_relation = GenericForeignKey('content_type', 'object_id')
    quantity = models.PositiveIntegerField(verbose_name=_('Quantity'), default=0)

And I'm working my admin.py this way:

class OrderItemInlineAdmin(GenericTabularInline):
    model = OrderItem
    min_num = 0
    extra = 0
    fields = ('item_relation', 'quantity',)
    ct_field = 'content_type'
    ct_fk_field = 'object_id'

class OrderAdmin(admin.ModelAdmin):
    list_display = ('user_form',)
    inlines = (OrderItemInlineAdmin,)

admin.site.register(Order, OrderAdmin)

I can't get my admin to show the OrderItem object inline (which can have a key to either a Product or an ExtraService) with my Order object, followed by its quantity field. Instead, it says the item_relation field is unknown:

FieldError at /admin/product/order/13/
Unknown field(s) (item_relation) specified for OrderItem

How do I bypass this?

PS: I've also tried using my own ModelForm but it still doesn't recognize the item_relation field.

PS1: If I don't define a fields variable in OrderItemInlineAdmin, I end up with something like this, which is incorrect because I have existing OrderItem objects and this assumes I don't (no object selected and no quantity?): not what I need

about 4 years ago · Santiago Trujillo
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