你好我想用复选框字段创建数据但是当我使用widget RadioSelect时数据无法保存在数据库中
这是forms.py
class VehicleAttribute(forms.ModelForm):
OPERATION = [('production','Production Vehicle'),('supporting','Supporting Vehicle')]
PAYLOAD_METER = [('yes','Yes'),('no','No')]
NUMBER_STRUT = [('0','0'),('3','3'),('4','4')]
operation = forms.ChoiceField(widget=forms.RadioSelect, choices = OPERATION)
payload_meter = forms.ChoiceField(widget=forms.RadioSelect, choices = PAYLOAD_METER)
number_of_strut_pressure = forms.ChoiceField(widget=forms.RadioSelect, choices = NUMBER_STRUT)
class Meta:
model = Vehicle_attribute
fields = ['operation','payload_meter','number_of_strut_pressure']
这是views.py
def data_vehicle_add(request):
if request.method == "POST":
form = VehicleAttribute(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.save()
return redirect('data_vehicle_add.html', pk=post.pk)
else:
form = VehicleAttribute()
return render(request,'data_vehicle_add.html', {'form':form}, context_instance=RequestContext(request))
你可以帮我解决这个问题吗?