Django

Code

Ticket #9025 (new)

Opened 10 months ago

Last modified 2 weeks 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 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.

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.

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




Change Properties
Action