Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » inlineformset_factory - minimum number of completed forms and custom validation [RSS Feed]

#1 June 19, 2010 19:54:55

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

inlineformset_factory - minimum number of completed forms and custom validation


Can anyone point me in the right direction regarding customer
validation of forms via an inlineformset_factory? I want to make sure
at least one form is completed and that no two forms have the same
date.

(I have to admit, I'm getting confused by how all the different
classes relate to each other)

I tried this below, but it doesn't even look as if it is getting
triggered when I'm debugging.

>>>>>>>>>>>>>>
'''Source :http://stackoverflow.com/questions/877723/inline-form-validation-in-django/1884760#1884760'''

class BaseAppointmentFormset(BaseInlineFormSet):
def is_valid(self):
return super(BaseAppointmentFormset, self).is_valid() and not
any()

def clean(self):
# get forms that actually have valid data
count = 0
for form in self.forms:
try:
if form.cleaned_data and not
form.cleaned_data.get('DELETE', False):
count += 1
except AttributeError:
# annoyingly, if a subform is invalid Django explicity
raises
# an AttributeError for cleaned_data
pass
if count < 1:
raise forms.ValidationError('You must have at least one
order')

AppointmentFormFactory = inlineformset_factory(Event, Appointment,
extra=7, max_num=7, can_delete=True, form=AppointmentForm,
formset=BaseAppointmentFormset)

formset = AppointmentFormFactory(instance=current_event)


>>>>>>>>>>>>>>>>>>>>

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

Offline

  • Root
  • » Django
  • » inlineformset_factory - minimum number of completed forms and custom validation [RSS Feed]

Board footer

Moderator control

Enjoy the 15th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support