views:

81

answers:

1

Hi there,

I just converted one of my models to use a generic foreign key. The model is working correctly with these, database is reporting correct values, and the API I have is working perfectly with the new foreignkey with zero change (Kept the same field name).

However, the admin totally fails. The Inline shows no data, despite there being some (see above). Here is my model code:

class CartItem(models.Model):
    cart = models.ForeignKey(Cart)
    quantity = models.PositiveIntegerField()
    price_item = models.DecimalField(max_digits=19, decimal_places=2)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(db_column="shop_item_id")
    shop_item = generic.GenericForeignKey("content_type", "object_id")

Fairly straightforward, right? admin.py looks like this:

class CartItemInline(generic.GenericTabularInline):
   model = CartItem 

class CartAdmin(admin.ModelAdmin):
   inlines = [
        CartItemInline,
   ]

Fun fact. If I add 'shop_item' to the fields tuple within the inline class I get this error:

'CartItemInline.fields' refers to field 'shop_item' that is missing from the form.

But .. it's there? I've tried everything and after 30 minutes I am just giving up on what is most likely a ridiculously simple to solve problem that my eyes simply cannot see today. :(

All this worked prior to using a GenericForeignKey so not sure what the issue could be anymore.

Thanks for any help.

A: 

Uhm...maybe

admin.site.register(CartItem, CartItemAdmin)

at the end of admin.py?

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#using-generic-relations-as-an-inline

I'm supposing this because you said "The Inline shows no data" so I'm guessing you didn't register it. I know it sounds stupid but that's what came on my mind.

dierre
It is registered, and you don't have to register inlines (But I tried it). Thanks for the help though
Bartek