is_empty() was indeed what I was looking for. :) For the time being I got it working using any(form.cleaned_data.values())
Thanks for your great help! 2B On Jul 2, 5:02 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2008-07-02 at 07:58 -0700, Berco Beute wrote: > > I have multiple instances of same the form (of which all fields are > > optional), but I only want to save the form in case something is > > filled in. How can I test that in my view? > > After checking that the form is valid (which means each field on the > form will have to have required=False, since the form could be entirely > empty), see if form.cleaned_data.values() contains anything. This > becomes a bit easier once newforms-admin lands because we essentially > implemented just that logic in the formsets there (and, from memory, > there's even an is_empty() method to save typing). > > If you want to have some fields required if and only if any data is > supplied, that's a little trickier. You still make each field optional > in the form, but then clean() method on the form can check if > cleaned_data contains anything and, if it does, check that *all* the > required fields are present. > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---