我一直在尝试根据我在视图中给出的内容来选择更改字段并获得
portfolio_portfolio
这是我的view.py
name 'self' is not defined
好的,我有一个模型
def CarOwnerSearch(request):
if request.user.is_authenticated():
form = carOwnerForm.__init__(self,'B','None','C')
return render (request,'carmanager/CarOwnerSearch.html', {'form': form})
这是我的model.py
class carOwnerForm(forms.ModelForm):
first_name = forms.charfield()
last_name = forms.charfield()
def __init__(self, a,b,c):
super(carOwnerForm,self).__init(a,b,c)
self.field["ownership_Type"].choice = [a,b,c]
class Meta:
model = CarOwner
fields = ['ownership_type','CarModel']
追溯就在这里 这是评论中提到的特定问题的编辑更新
答案 0 :(得分:2)
这是您初始化表单的方式:
form = carOwnerForm.__init__(self,'B','None','C')
应该是
form = carOwnerForm('B', None, 'C')