Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CombinedFormSet(BaseInlineFormSet):
- # Validate formset data here
- def clean(self):
- super(CombinedFormSet, self).clean()
- for form in self.forms:
- if not hasattr(form, 'cleaned_data'):
- continue
- data = self.cleaned_data
- valid = False
- for i in data:
- if i != {}:
- if i['is_correct']:
- valid = True
- if not valid:
- #TODO: translate admin?
- raise forms.ValidationError("A Question must have an answer.")
- # Always return the cleaned data, whether you have changed it or
- # not.
- return data
- class ChoiceInline(admin.TabularInline):
- model = Choice
- extra = 4
- formset = CombinedFormSet
Advertisement
Add Comment
Please, Sign In to add comment