Tuesday, October 28, 2014

Rendering TabuarInline inside ModelAdmin without a foreign key

Hi list,

I have a table of orders where one of the columns is a IntegerField containing the id of a user who created the order. 

Since it's not a FK field django admin can't display these orders inline inside the user details page.

I would normally use something like:

class OrderInline(admin.TabularInline):
    extra = 0
    model = Order

And then add that to the user model like this:

inlines = [OrderInline]

But it won't work without the FK.

I've Googled around and tried everything I found on SO but I can't figure out how to add orders inline to my user model.

I'm looking at https://docs.djangoproject.com/en/dev/_modules/django/contrib/contenttypes/admin/#GenericTabularInline and I'm thinking do I need to write a similar class or is there something easy and simple I'm missing.

Cheers,

Mario


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHqTbjkzDTZ54v1-uZPTdTSgApQTnySKGAvZ%2BzZjqH0g4fUB%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment