我想将模型“modelToUse”传递给我的表单:
class ActsAddForm(forms.Form):
def __init__(self,*args,**kwargs):
self.modelToUse = kwargs.pop('modelToUse')
super(ActsAddForm,self).__init__(*args,**kwargs)
actsToValidate=forms.ModelChoiceField(queryset=modelToUse.objects.filter(validated=0), empty_label="Select an act to validate", widget=forms.Select(attrs={'onchange': 'this.form.submit();'}))
我收到错误“未定义名称'modelToUse'”。怎么了?
我想在我看来这样称呼它:
addForm=ActsAddForm(modelToUse=ActsIdsModel())