创建新的BookStore对象时,我正在尝试初始化django 1.8管理页面的嵌入式表单集,已经列出了许多默认书籍:
from django.forms import formset_factory
class BookInlineAdmin(admin.TabularInline):
model = Book
form = BookForm
extra = 1
def get_formset(self, request, obj=None, **kwargs):
formset = super(BookInlineAdmin, self).get_formset(request, obj, **kwargs)
BookFormSet = formset_factory(BookForm, extra=4)
formset = BookFormSet(initial=[
{'stype': 'comic', 'name': 'abc'},
{'stype': 'drama', 'name': 'aaa'}])
return formset
但是,它失败了:
TypeError:“ BookFormFormSet”对象不可调用
如何初始化为管理页面设置的嵌入式表单?