How to I show a list of ForeignKey reverse lookups in the DJango admin interface? -


i have couple of models:

class customer(models.model):     customer_name = models.charfield(max_length=200)      def __unicode__(self):         return self.customer_name      class meta:         ordering = ('customer_name',)  class unit(models.model):     unit_number = models.integerfield()     rentable = models.booleanfield()     owner = models.foreignkey(customer, related_name='units', blank=true, null=true)      def __unicode__(self):         return str(self.unit_number)      class meta:         ordering = ('unit_number',) 

i have admin interface working fine when i'm adding unit (i can select customer assign to) when go create/edit customer in django admin interface, doesn't list units choose from. how can enable lookup in section match 1 in create/edit customer area?

by default, modeladmin let manage model "itself", not related models. in order edit related unit model, need define "inlinemodeladmin" - such admin.tabularinline - , attach customeradmin.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

for example, in admin.py:

from django.contrib import admin models import customer, unit  class unitinline(admin.tabularinline):     model = unit  class customeradmin(admin.modeladmin):     inlines = [         unitinline,     ] admin.site.register(customer, customeradmin) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -