Hi Shawn, I am referring to forms.ModelForm, I think it might apply to forms as well, but I can't think of a good use case off the top of my head.
I suppose I might have an uncommon use case. I display a form that has several optional parts (that have different models) that can be dynamically added with ajax and I wanted to avoid adding blank entries to the database - but partially filled ones would be okay since the user indicated that they have something to share. I can always just patch my own version or work around it, but I was wondering if this was common enough to be of interest to someone else. -AM On Dec 24, 3:02 pm, Shawn Milochik <sh...@milochik.com> wrote: > On Dec 24, 2009, at 2:51 PM, Aristotle Miternan wrote: > > > > > > > Hello all, > > > I'm fairly new to Django and I noticed a curious behavior of > > forms. I noticed that there is no simple way to test a form for a form > > not being filled at all. I think it might be a semi-common use case > > that you might want to simply not generate a new model instance if a > > form has no information in it rather than return an error. This sort > > of thing would look something like: > > > form.is_blank() ( analogous to form.is_valid() ) > > > As it is, you have to mark all parts of the form as blank=True and > > then scan through them. The thing is, if any of them are filled out > > then I don't want blank=True on my fields, but I do want to test if > > everything is blank painlessly. > > > I'm new at this, so there might be an idiom I don't know of or there > > might be a good reason why this is a bad idea. > > > Thank you for reading! > > -AM > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > Well, are you talking about a forms.Form or a forms.ModelForm? A ModelForm > will require any fields that are required in the model. > > A Form's fields default to being required, unless you specify otherwise. Any > fields not filled will return a message to the user. > > It sounds like you want a way to know whether all the fields are blank, but > if the field is invalid, what does that matter? It can't be processed if one > required field is left blank or if all of them are. What is your use-case for > wanting to know exactly how much of the form is blank? > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.