hi all,
really, I don't get this model form validation stuff. And currently, right now, I am immensely p*** off, because either the documentation is horribly bad (at least for me) or I am simply way too stupid.
okay, enough rant, let's get practical - on to my little problem. I want to do model formset validation.
I have a modelform like the one below. And I wanted to intercept the is_valid() method of the modelform, to prepare some stuff before the standard validation kicks in. But, the fun fact is, is_valid NEVER gets called - at least my breakpoints in that method are not hit. The clean() method does get called, but this one is totally useless to me ... here the validation seems to be done already. I also have the funny little thing that the TimeInput fields are not in the cleaned_data dict, but that's another thing maybe.
Can anyone help me out here, please? That can't be that hard ...
Thanks in advance & greetings,
Axel.
class LegForm(forms.ModelForm):
class Meta:
model = Leg
widgets = { 'flownmission' : widgets.HiddenInput(),
'blockoff' : widgets.TimeInput( attrs={ 'size':10 } ),
'takeoff' : widgets.TimeInput( attrs={ 'size':10 } ),
'landing' : widgets.TimeInput( attrs={ 'size':10 } ),
'blockon' : widgets.TimeInput( attrs={ 'size':10 } ),
'num_landings' : widgets.TextInput( attrs={ 'size': 5 } ),
}
def is_valid(self):
return True # never EVER gets called
def clean(self):
super(forms.ModelForm, self).clean()
return self.cleaned_data
@login_required
def addlegs(request, mission_id=None):
LegFormSet = modelformset_factory(Leg, form=LegForm, extra=3)
if not request.method == "POST":
# if mission_id is set we're being called from another method in here ... :)
formset = LegFormSet(queryset=Leg.objects.none())
return rtr(request, 'flightlog/templates/addlegs.html', {"formset":formset})
else:
formset = LegFormSet(request.POST)
formset.is_valid()
return redirect("/")
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment