Django: How to save a formset with a custom model form? -


trying save bunch of objects custom form:

class customform(forms.modelform):     class meta:         model = widget     complexify = models.booleanfield() 

when complexify checked, need complex operations on widget object.

i can't do:

for object in formset.save(commit=false):     ... 

because won't have complexify flag.

and going through each form seems wrong way:

for form in formset.forms:     ... 

because includes (empty) forms , deleted forms.

any ideas on how done?

the best answer find problem overriding save on form:

class customform(forms.modelform):     class meta:         model = widget     complexify = models.booleanfield()      def save(self, *args, **kwargs):         obj = super(customform, self).save(*args, **kwargs)         obj.complexify = self.cleaned_data.get("complexify")         return obj 

then available when handle them:

for object in formset.save(commit=false):     if object.complexify:          object.do_complicated() 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -