Django

Code

Ticket #9025 (new)

Opened 2 years ago

Last modified 1 day ago

Nested Inline Support in Admin

Reported by: pixelcort Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk, gonz, alexkoshelev Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

Description

Currently, admin.TabularInline? and admin.StackedInline? do not support inlines themselves.

This would allow nested inlines to happen.

Attachments

django_nested_inlines.diff (4.4 kB) - added by vo.sinh@gmail.com on 11/04/08 22:16:07.
nested_inlines.diff (8.4 kB) - added by schinckel on 11/17/09 18:34:24.
Alternate patch: against trunk

Change History

09/18/08 15:34:26 changed by anonymous

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

SOMEONE DO THIS!!!!

09/24/08 20:47:59 changed by knoffhoff

  • cc set to steffen.jasper@descript.de.

09/29/08 18:47:12 changed by anonymous

  • cc changed from steffen.jasper@descript.de to steffen.jasper@descript.de, cortland@apple.com.

10/23/08 10:41:30 changed by Fugazi

  • component changed from Contrib apps to django.contrib.admin.

anybody can fix this ?

11/04/08 22:16:07 changed by vo.sinh@gmail.com

  • attachment django_nested_inlines.diff added.

11/04/08 22:22:06 changed by vo.sinh@gmail.com

  • needs_better_patch set to 1.
  • has_patch set to 1.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Design decision needed.

I attached a patch to enable nested inlines with a depth level of 3 on the change_view of ModelAdmin? depth level of 3 means it is limited to something like: A.inlines[ B ] B.inlines [ C ] C.inlines [ D ]

It's just an experiment to see if it was easily doable so the code is not that great

11/04/08 22:27:17 changed by anonymous

  • cc changed from steffen.jasper@descript.de, cortland@apple.com to steffen.jasper@descript.de, cortland@apple.com, vo.sinh@gmail.com.

01/08/09 19:48:30 changed by knoffhoff

  • cc changed from steffen.jasper@descript.de, cortland@apple.com, vo.sinh@gmail.com to cortland@apple.com, vo.sinh@gmail.com.

(in reply to: ↑ description ; follow-up: ↓ 9 ) 01/28/09 09:22:30 changed by anonymous

Replying to pixelcort:

Currently, admin.TabularInline? and admin.StackedInline? do not support inlines themselves. This would allow nested inlines to happen.

Has the attached patch been tested? Anything special in the admin.py configuration? It is not working for me, although the code with the patch was translated successfully. Thanks for a reply.

(in reply to: ↑ 8 ; follow-up: ↓ 10 ) 01/29/09 19:07:47 changed by vosinh

Replying to anonymous:

Replying to pixelcort:

Currently, admin.TabularInline? and admin.StackedInline? do not support inlines themselves. This would allow nested inlines to happen.

Has the attached patch been tested? Anything special in the admin.py configuration? It is not working for me, although the code with the patch was translated successfully. Thanks for a reply.

I wrote it for a project with a very large number of tables (>100) and with 3 or 4 levels of relations depth between tables very often and doing a specific admin page for every table set would be big work (20+ sets, and more could be added). the code gives you the possibility to do multiple inlines like:

class rab_Inline(TabularInline?):

model = rab

class bar_Inline(TabularInline?):

model = bar inlines = [rab_Inline]

class foo_Admin(AdminModel?):

model = foo inlines = [bar_Inline]

with code like this in your admin.py you have the three tables in the foo object admin page is this working for you? I tested it with 1.0 and 1.0.1. I'm going to upgrade to 1.0.3 soon and test with it too, but it should work

the part that's missing from the patch is EDITING support. You are not able to edit. I took a look at it for a bit but since I dont need it i never implemented it. I remember there's code that puts all the generated html form code in a list, but if you have multiple inlines the order is wrong and only the first added forms can work (the foo object form should work). Expanding that code should add editing support. If you are interest I can provide more details

(in reply to: ↑ 9 ) 01/29/09 19:10:34 changed by vosinh

Replying to vosinh:

Replying to anonymous:

Replying to pixelcort:

Currently, admin.TabularInline? and admin.StackedInline? do not support inlines themselves. This would allow nested inlines to happen.

Has the attached patch been tested? Anything special in the admin.py configuration? It is not working for me, although the code with the patch was translated successfully. Thanks for a reply.

I wrote it for a project with a very large number of tables (>100) and with 3 or 4 levels of relations depth between tables very often and doing a specific admin page for every table set would be big work (20+ sets, and more could be added). the code gives you the possibility to do multiple inlines like: class rab_Inline(TabularInline?): model = rab class bar_Inline(TabularInline?): model = bar inlines = [rab_Inline] class foo_Admin(AdminModel?): model = foo inlines = [bar_Inline] with code like this in your admin.py you have the three tables in the foo object admin page is this working for you? I tested it with 1.0 and 1.0.1. I'm going to upgrade to 1.0.3 soon and test with it too, but it should work the part that's missing from the patch is EDITING support. You are not able to edit. I took a look at it for a bit but since I dont need it i never implemented it. I remember there's code that puts all the generated html form code in a list, but if you have multiple inlines the order is wrong and only the first added forms can work (the foo object form should work). Expanding that code should add editing support. If you are interest I can provide more details

tested with 1.0 and 1.0.1 but not 1.0.2 1.0.3 is typo

02/25/09 05:36:49 changed by DenisCheremisov

Did this patch include into testing?

04/25/09 07:57:04 changed by mrts

  • keywords set to admin-refactor.
  • version changed from 1.0 to SVN.

To give more context why this is useful, let me illustrate this with a common use case.

Suppose you model events that can have one or more occurrences.

Each occurrence has a single location and one or more time slots (e.g. a theatre performance that takes place in hall A on Tuesday and Wednesday and in hall B on Saturday.)

You get the following model structure:

class Event(models.Model):
    name = models.CharField(max_length=255)

    def __unicode__(self):
        return self.name

class Location(models.Model):
    name = models.CharField(max_length=255)

    def __unicode__(self):
        return self.name

class Occurrence(models.Model):
    event = models.ForeignKey(Event)
    location = models.ForeignKey(Location)

class TimeSlot(models.Model):
    occurrence = models.ForeignKey(Occurrence)
    start = models.DateTimeField()
    end = models.DateTimeField()

For the admin, you need occurrences to be displayed when you edit the events. The occurrences themselves need to display times lots. Thus, inline nesting is needed:

class TimeSlotInline(admin.TabularInline):
    model = TimeSlot
    extra = 1

class OccurrenceInline(admin.TabularInline):
    model = Occurrence
    inlines = (TimeSlotInline,)
    extra = 2

class EventAdmin(admin.ModelAdmin):
    inlines = (OccurrenceInline,)

admin.site.register(Event, EventAdmin)
admin.site.register(Location)

A design decision is also needed on how deep the nesting should be. It's possible to support arbitrarily deep nesting with recursion, whether that's feasible or necessary remains open. Perhaps an extension mechanism should be provided so that API users can control the inlines and nesting.

The result could look like this:

http://img524.imageshack.us/img524/9852/nestedadmin.png

04/25/09 09:31:04 changed by mrts

  • keywords changed from admin-refactor to gsoc09-admin-refactor.

04/25/09 10:34:27 changed by jacob

  • keywords deleted.

06/21/09 20:42:59 changed by Henry Andrews <hha1@cornell.edu>

  • cc changed from cortland@apple.com, vo.sinh@gmail.com to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu.

07/09/09 09:30:54 changed by arj

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk.

07/16/09 12:05:00 changed by kilpatds

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org.

09/23/09 07:00:26 changed by hejsan

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni@gmail.com.

09/23/09 07:02:38 changed by hejsan

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni@gmail.com to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com.

09/24/09 08:19:59 changed by martinlindholdt

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com.

10/02/09 13:15:47 changed by mareczekp

I've managed to partially made this patch work for version 1.2 pre-alpha (svn release).

When I go to the adding site the inlines of an inline are being displayed but unfortunately whenever I want to add or save an edit something is crashing.

Is there a working (valid) patch for later versions of django (eg. 1.1)?

Thanks and appreciate the work that you guys contribute. If you want to me to show the changes I had to make to get it work please ask. It wont be a problem.

best regards. mp

10/13/09 08:26:46 changed by ruosteinen

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi.

10/29/09 05:38:36 changed by vinilios@gmail.com

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com.

11/13/09 19:16:16 changed by schinckel

I've been putting a bit of effort into this today, and I have come to the conclusion that the method for doing this in the patch is flawed.

It attempts to associate the nested inlines with the base admin model. I think that there probably shouldn't be many changes to the ModelAdmin? class, but that they should all be in InlineModelAdmin?.

11/17/09 04:15:56 changed by mmarcos

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org.

11/17/09 18:33:12 changed by schinckel

I have got some code working, and attached a patch if anyone else is interested.

Basically, I have slightly modified the ModelAdmin? class to include the nested inlines in the change page (I haven't worried about the add page at this stage).

Then, the InlineModelAdmin? has changes to create the inline formsets. Finally, there are a couple of template changes, including a new template for the nested formsets.

I have made a couple of design decisions that reflect my use case for the project I am working on, mainly that I don't have add page support, and only include the nested inlines in a TabularInline?. Each class of inline is a seperate column, and each instance of the related object is a sub-row in that column.

I have an example image: http://s3.amazonaws.com/ember/HGETbz2gS1IXvDlOB3idRmcp0ocFL1VK_l.png

(Note that this uses the Inline properties on this class to not show more than 2, and none if the object is not saved).

11/17/09 18:34:24 changed by schinckel

  • attachment nested_inlines.diff added.

Alternate patch: against trunk

11/24/09 18:18:04 changed by gmorehoudh

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net.

12/07/09 11:26:52 changed by anonymous

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk.

02/25/10 07:32:13 changed by gonz

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk, gonz.

03/19/10 03:44:55 changed by alexkoshelev

  • cc changed from cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk, gonz to cortland@apple.com, vo.sinh@gmail.com, hha1@cornell.edu, anders@iola.dk, kilpatds@oppositelock.org, hr.bjarni+django@gmail.com, martin@smallstorm.com, tommi@syneus.fi, vinilios@gmail.com, mmarcos@rodesia.org, wnvnqxoq@trashmail.net, james@dropp.co.uk, gonz, alexkoshelev.

Add/Change #9025 (Nested Inline Support in Admin)




Change Properties
Action