Monday, April 30, 2012

Problem with a clean in inline formset


The (if display.max_windows() >= works fine to
prevent insert. Behaves as expected.
But is raised even when the row is REMOVED from the edit formset. =/

## Models

class Display(models.Model):
windows = models.IntegerField()

def max_windows(self):
total = self.window_set.all().count() #window is a
intermediary class to campaign
if total:
return total

## Clean method in CampaignInlineFormSet

def clean(self):
if any(self.errors):
# Don't bother validating the formset unless each form is
valid on its own
for i in range(0, self.total_form_count()):
form = self.forms[i]
cleaned_data = form.clean()
display = cleaned_data.get('display', None)
if display.max_windows() >=
raise forms.ValidationError("The display have all
windows occupied.")

This "if" can not stop me remove a row in inline formset. How can I
fix this?

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment