Django Inlining shows additional fields in the add dialog -
i wrote django 1.7.7 code:
class color(models.model): color = models.charfield(max_length=20, primary_key=true) def __unicode__(self): return str(self.color) class pen(models.model): label = models.charfield(max_length=20, primary_key=true) color = models.foreignkey('color') class penadmin(admin.modeladmin): pass class peninline(admin.tabularinline): model = pen class coloradmin(admin.modeladmin): inlines = [peninline,] admin.site.register(pen, penadmin) admin.site.register(color, coloradmin)
i want know why when click on add color button in admin page, shows 3 pen fields in image below , how remove them specific dialog. i've tried both tabularinline , stackedinline , identical.
inlinemodeladmin
extra
's default value 3
, can change extra = 0
in peninline
declaration:
class peninline(admin.tabularinline): model = pen = 0
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.inlinemodeladmin.extra
or @ https://stackoverflow.com/a/2228821/3033586
or remove coloradmin
declaration , change last line admin.site.register(color)
Comments
Post a Comment