0

hallo i want to create data with checkbox field but data cannot save in database when i use widget RadioSelect

this is 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']

this is 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))

can you help me solve this problem?

chandu
  • 1,053
  • 9
  • 18
User0511
  • 665
  • 3
  • 11
  • 27
  • 1
    Any errors? *why* can't it save – Sayse Aug 11 '15 at 06:28
  • No error. because i use ChoiceField. When I am delete ChoiceField Data can save in database. how? – User0511 Aug 11 '15 at 06:30
  • I'm afraid I can't understand what the problem is, It does sound like there would be an error at some point though, set a breakpoint and verify the form is valid. If it isn't, look in `form.errors`, if it is, continue to step through. – Sayse Aug 11 '15 at 06:33
  • thanks i use form.errors to find invalid form. its works :) – User0511 Aug 11 '15 at 06:36
  • do this instead of the two lines save "post = form.save()" – Du D. Aug 11 '15 at 14:38

0 Answers0