Models.py:
class ExperienceSynopsis(Audit):
user = models.ForeignKey(User, null = True, blank = True)
area_skill = models.CharField(max_length = 50, help_text = 'Example: Testing,Development,etc..')
experience = models.CharField(max_length = 50)
def __unicode__(self):
return self.area_skill
Forms.py:
class ExperienceSynopsisForm(forms.Form):
area_skill = fields.CharField(max_length=50, help_text = 'Example: Testing,Development,etc..')
experience = fields.CharField(max_length=50)
ExperienceFormset = formsets.formset_factory(ExperienceSynopsisForm, formset = RequiredFormSet, extra = 0)
我想在admin.py中添加formset。如何启用此模型的管理员。请帮助我。
答案 0 :(得分:4)
Django文档和教程给出了一个如何工作的开头
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.StackedInline
将您的Formset添加到Inline对象,然后设置
class BookInline(admin.TabularInline):
model = Book
formset = # Yours
class AuthorAdmin(admin.ModelAdmin):
inlines = [
BookInline,
]
如果需要,使用save_formset
覆盖保存