django admin duplicating inlines
For some reason, in my admin site I am seeing a specific inline getting duplicated. I have the following models:
class PageBase(ContentContainer):
title = models.CharField(max_length=1000)
slug = models.SlugField()
class PageBanner(models.Model):
name = models.CharField(max_length=1000)
page = models.ForeignKey(PageBase)
banner_images = models.ManyToManyField(BannerImage)
Then in my admin.py I have:
class PageBannerInline(admin.StackedInline):
model = models.PageBanner
extra = 1
class PageAdmin(admin.ModelAdmin):
model = models.Page
inlines = PageBannerInline
admin.site.register(models.Page, PageAdmin)
admin.site.register(models.PageBanner, PageBannerAdmin)
For some reason, every time I add a PageBanner to any page in the admin, thus creating another inline for that page, I get anot开发者_开发知识库her extra banner inline on EVERY page(including the one I added on).
So, if I have 4 pages and each page has 1 banner, I will see 3 extra inlines on every page.
What is going on here? This is quickly becoming unmanageable, the inlines take up way too much space.
Here is an image of the inlines:
AFAIK, it's the default behavior of Django to add 3 forms for your inline model, so you can add 3 instances at once. You should be able to change that with the 'extra' attribute:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.extra
精彩评论