Wednesday, October 29, 2014

Re: Rendering TabuarInline inside ModelAdmin without a foreign key

On Wednesday, 29 October 2014 03:57:36 UTC, somecallitblues wrote:
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 don't show your models, but why is it not a ForeignKey? After all, a FK field is exactly what you describe, an integer field that contains the ID of the model it is pointing to. So why not declare it as one?
--
DR. 

--
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/fc21c60e-5a33-4e10-9f48-42c2c8c43c7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment