我最终遇到此错误:
元类冲突:派生类的元类必须是其所有基元元类的(非严格)子类
我唯一要做的就是传递一个参数来过滤查询集。该文档显示了一个简单的案例。
forms.py:
class BaseEducationFormSet(BaseModelFormSet):
def __init__(self, *args, **kwargs):
id = kwargs.pop('curriculum_fk')
super().__init__(*args, **kwargs)
self.queryset = Education.objects.filter(curriculum__id=id)
views.py:
def cv_edit(request, pk):
EducationFormSet = modelformset_factory(Education, fields = ('title', 'institution', 'place') , formset=BaseEducationFormSet(curriculum_fk=pk))
尽管我可以通过“ modelformset_factory”来完成这项工作...