I am trying to perform custom validation on an inline formset.  The
docs indicate that custom formset validation should go through a
custom clean method:

http://docs.djangoproject.com/en/1.1/topics/forms/formsets/#custom-formset-validation

but the clean method doesn't get called for my instance of an inline
formset when I call is_valid() on the formset.

Conceptually, I have Client model with many PhoneNumber models for my
inline formset, and want to do some validation on the phone number
fields based on fields in client.  The relevant code snippets for my
project:

custom form code:

class BaseClientPhoneInlineFormSet(BaseInlineFormSet):
  # do nothing pass-through method, but see that logging statement
prints
  def __init__(self, data=None, files=None, instance=None,
               save_as_new=False, prefix=None):
    logging.debug("IN client.forms.BaseClientPhoneFormset.__init__")
    super(BaseClientPhoneInlineFormSet, self).__init__(data, files,
instance, save_as_new, prefix)

  # this should do validation, but doesnt.  this logging statement
never prints
  def clean(self):
    logging.debug("IN client.forms.BaseClientPhoneFormset.clean")
    super(BaseClientPhoneInlineFormSet, self).clean()
    raise forms.ValidationError("Test Inline Formset Clean Fail.")


view code:

  ClientPhoneFormSet = inlineformset_factory(models.Client,
models.PhoneNumber, formset=BaseClientPhoneInlineFormSet)
  formset = ClientPhoneFormSet(request.POST, instance=client_ref)
  formset.is_valid():  # no validation error thrown, returns true


The __init__ logging message is output, but the clean logging message
is not, and no ValidationError is thown on is_valid().

I've searched and not found any similar questions which makes me think
I'm missing something obvious :-/

Thanks for any help.

dan

-- 
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.

Reply via email to