BaseModelFormSet“元类冲突”

2024-10-01 00:19:25 发布

您现在位置:Python中文网/ 问答频道 /正文

跟随django docs

我最后犯了一个错误:

metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

我唯一改变的是传递一个参数来过滤查询集。医生说了一个更简单的例子。你知道吗

你知道吗表单.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)

你知道吗视图.py: 你知道吗

def cv_edit(request, pk):
    EducationFormSet = modelformset_factory(Education, fields = ('title', 'institution', 'place') , formset=BaseEducationFormSet(curriculum_fk=pk))

我以为“模型工厂”能处理这项工作。。。你知道吗


Tags: ofthepyselfidinitdefargs