Django displaying one to many relationship in the admin page

Viewed 2803

Database example:

class Brand(models.Model):
  brand_name = models.CharField(max_length=30


class Model(models.Model):
  brand = models.ForeignKey(Brand)
  model_name =  models.CharField(max_length=30)

Now in admin

admin.site.register(Brand)

class ModelAdmin(admin.ModelAdmin):
  list_display = ['brand', 'model_name']
  fields = ['model_name', 'brand']
admin.site.register(Model, ModelAdmin)

How can I show in the BrandAdmin page all the models that are associated with the one brand? As it stands right now, the Brand page only shows the brands, it doesn't show any of the models associated with it.

1 Answers
Related