You override the save in two places, in the form itself or in the
view. Either one would work, you could combine the two as well.
the form save override would look something like
def save(self):
formatform = super(FormFormat, self).save(commit=False)
if formatform.boolean1 and formatform.boolean2:
formatform.myBoolean = True
formformat.save()
in the view:
form = FormFormat(request.POST)
if form.is_valid():
form_save = form.save(commit=False)
if form_save.boolean1 == True and form_save.boolean2 == True:
form_save.myBoolean = True
form_save.save()
On Aug 11, 2:08 pm, Roald de Vries <[email protected]> wrote:
> On Aug 11, 2010, at 7:25 PM, refreegrata wrote:
>
>
>
> > My code
> > ----------------------------------
> > class Format(models.Model):
> > name = models.CharField(max_length=5, unique=True)
> > myBoolean = models.BooleanField(default=False)
>
> > class FormFormat(forms.ModelForm):
> > boolean1 = forms.BooleanField(required=False)
> > boolean2 = forms.BooleanField(required=False)
>
> > class Meta:
> > model = Format
> > fields = ['name']
>
> > FormsetFormFormat = forms.models.modelformset_factory(Format,
> > max_num=0,form=FormFormat)
> > ----------------------------------
> > The idea is this:
>
> > if boolean1=True and boolean2=True the field myBoolean must to be True
> > if boolean1=True and boolean2=False the field myBoolean must to be
> > False
> > ...
> > My question is, how i can do this?
> > overwriting the save method?
>
> Possible, but I have a feeling there might be a nicer solution. What
> do you want to happen if boolean1 is false?
>
> > I don't have idea, because boolean1 and boolean2 are form fields not
> > model fields. Can i pass custom parameters to the save method?
>
> Yes, you can.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.