views:

146

answers:

1

Hi,

I'm writing an app that have recursive relations like this (pseudocode):

class atist:
      name = charfield 
      (...)

class press:
      pub = foreingkey(artist)

class works:
      work = foreingkey(artist)

class img:
      im = foreingkey(works)

I'm was thinking if this is the better approach to solve this problem, or if i would use another kind of relation like many to many? and for other side how i can regist this app in the admin site to have only one page for artist with works and press as inline objects of artist?

thanks

+3  A: 

If a works, img or press will only ever relate to one artist, then you don't need a many to many, so the way you have it setup in your pseudo-code should suffice.

You can check out the inline froms for the admin. You can specify things such as how many inline items to show of each type, etc.

class MyModelInline(admin.StackedInline):
      model = MyModel
      # whatever other options you need for your inline

class MyModelAdmin(admin.ModelAdmin):
      inlines = [MyModelInline,]

Something like that should work for you. Like AlbertoPL said, there's more info in the docs with all the different options and functionality that you'd need.

Alex Jillard