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

245
Views
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
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!