Monday, May 21, 2012

Re: Nested Foreign Key relationships in Admin?

On 21/05/2012 2:55pm, Mike Dewhirst wrote:
> On 21/05/2012 2:45pm, Mike Dewhirst wrote:
>> On 21/05/2012 1:57pm, Aditya Sriram M wrote:
>>> I'd like to represent foreign key relationships inside the Admin
>>> interface when there are multiple nested one-to-many relationships.
>>
>> Provided you have the admin app enabled, in your admin.py in the same
>> directory as your models.py file you need some nested classes ...
>>
>> class RootAdmin(admin.ModelAdmin):
>> # any ModelAdmin options
>>
>> class Model2Admin(admin.TabularInline): # or admin.StackedInline
>> # any TabularInline options
>>
>> class Model3Admin(admin..TabularInline): # or
>> admin.StackedInline
>> # any TabularInline options

On 21/05/2012 7:26pm, Matt Schinckel wrote:
> The admin.*Inline objects will not render nested inlines.
>
> See https://code.djangoproject.com/ticket/9025
>
> Matt.

As Matt pointed out the Model3 inline won't be nested. But you can
un-indent it to the same level as the Model2 inline and both will be
editable within the RootAdmin. I have done this previously and just
assumed it would work at an extra level. I'll try to avoid that in future.

Mike

> Actually, I meant to name the nested classes more appropriately as
> Model2Inline() and Model3Inline().
>
> Then at the bottom of the admin.py file you need ...
>
> admin.site.register(Root, RootAdmin)
>
> ... which includes the ModelxInlines because they are nested in your
> code.
>
> Mike
>
>
>>
>> ... which ought to give you a nested view of Model2 when you examine
>> Root in the admin and a nested view of Model3 inside Model2. You can
>> use whatever options are listed in the docs (see below) to control
>> what happens when displaying records in the Admin app..
>>
>> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects
>>
>>
>> Mike
>>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate