python - How to enable Django management interface for foreign keys? -


https://docs.djangoproject.com/en/1.4/ref/models/relations/ gives model definition , code examples of using one-to-many , many-to-many relationships. neither reference nor tutorial (https://docs.djangoproject.com/en/1.4/intro/tutorial02/) give administration examples foreign keys.

using following models relations examples:

class reporter(models.model):     name = models.charfield()  class article(models.model):     title = models.charfield()     reporter = models.foreignkey(reporter)  class topping(models.model):     flavor = models.charfield()  class pizza(models.model):     type = models.charfield()     toppings = models.manytomanyfield(topping) 

(each model includes unicode() def, omitted brevity.) , after registering each in admin.py:

admin.site.register(reporter) admin.site.register(article) admin.site.register(topping) admin.site.register(pizza) 

the admin interface allows creation of instances of each of 4 types. when managing articles shows picklist select reporter. when managing reporters there no list of articles.

similarly managing pizza shows selection list of toppings, managing toppings not show list of pizza types using topping.

how 1 modify admin.py enable automatic management of reporter.article_set , topping.pizza_set relations?

------------ edit ------------

in attempt simplify question, oversimplified. actual pizza models , admin interface i'm using are:

class topping(models.model):     flavor = models.charfield(max_length=32)     quantity = models.integerfield()  def __unicode__(self):     return self.flavor  class pizza(models.model):     type = models.charfield(max_length=32)     toppings = models.manytomanyfield(topping)     price = models.decimalfield(max_digits=5, decimal_places=2)  def __unicode__(self):     return self.type 

and

class toppinginline(admin.tabularinline):     model = topping     = 3  class pizzaadmin(admin.modeladmin):     filedsets = [(none,  {'fields':['type', 'price']})]     inlines = [toppinginline]  admin.site.register(topping) admin.site.register(pizza, pizzaadmin) 

and article / reporter model i'm using similar - many-to-many field because 1 reporter can have multiple articles , 1 article can have several authors. poll example in tutorial shows one-to-many mapping question choices, , straightforward extension of tutorial's polladmin pizzaadmin fails using django 1.4 on openshift origin 3.0.

so there guidance or tutorial on how write admin.py works manytomanyfield? poll example doesn't work here because eliminates ability administer choices separately questions. comparable 1 should able create catalog of choices (by administering choices) , questions interface able select choices apply question not able modify content of choice.

inlinemodeladmin want. can either use stackedinline or tabularinline.

step 1: create new tabularinline class or stackedinline class articles:

class articleinline(admin.tabularinline):     model = article 

step 2: create modeladmin class reporter inline created above:

class reporteradmin(admin.modeladmin):     inlines = [         articleinline,     ] 

step 3: register modeladmin modelclass:

admin.site.register(reporter, reporteradmin) 

btw: should really upgrade 1.4 newer django release


Comments