1

Part of the model of an app I'm trying to build with django is based on a three-tier structure, like this :

 class A(models.Model):
     name = models.TextField()

 class B(models.Model):
     related_A = models.ForeignKey(A)
     info = models.TextField()

 class C(models.Model):
     related_B = models.ForeignKey(B)
     other_infos = models.TextField()

So A is composed of some Bs, which are composed of some Cs. Since Django admin doesn't accept nested inline forms yet, I was thinking the ideal way of doing it would be with this sort of workflow : there would be a "A admin page", which would get me a link to click called "Add some Bs to this A", and offer me a page with a B form using inline C forms.

Is there a way to do this simply from the Admin website that I didn't see, or should I consider extending the admin default application ?

Some clarification

Let's say you make statistics about Continent, Countries and Regions. My goal is to have a clear structure to add a Country to a Continent and a Region to a Country. Ideally, a user of the administration interface won't be able to add "immediately" a Country ; she or he needs to go through a page where he'll have to select a Continent. Ideally, there would be one single page for the Continent, containing an inline form of country, each of those forms having an inline form of regions.

Since nested inline forms do not seem to be a feature in Django 1.3, I'm looking for a way to have a sort of "workflow" in the administration site : the user would first click on "Continent" in the first screen ; it would then show a list of continents ; clicking on a continent would show a list of the countries associated to this continent ; finally, the user could edit a Country form, displaying some inline region forms to allow adding country and region on the same page.

I hope this concrete exemple make it easier to understand...

Raveline
  • 2,660
  • 1
  • 24
  • 28

2 Answers2

0

U can use GenericForeginKey() to solve the limitation problem.

Ref https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/

dilip kumbham
  • 703
  • 6
  • 15
0

The easiest way is to use Country as a start point: in its form page you could inline edit Region as well as force staff to choose from existed Continents or add new one by clicking +.

You could also modify ModelAdmin to open Country page and populate pk of a saved Continent to it, which is more difficult. Check this post also.

Furthermore, it's possible to mimic a ForeignKey pointing to A in C, and inline editing both B and C in A, just as GenericForeignKey does. However, it's hard and overkilled for most usages...

Community
  • 1
  • 1
okm
  • 23,575
  • 5
  • 83
  • 90