Provides a better error message when a sponsor benefit text field is longer than the allowed limit.
It tells you how many words you've written!
This commit is contained in:
parent
475b32f4bb
commit
0a597d38bf
1 changed files with 5 additions and 2 deletions
|
@ -194,8 +194,11 @@ class SponsorBenefit(models.Model):
|
||||||
return u"%s - %s" % (self.sponsor, self.benefit)
|
return u"%s - %s" % (self.sponsor, self.benefit)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.max_words and len(self.text.split()) > self.max_words:
|
num_words = len(self.text.split())
|
||||||
raise ValidationError("Sponsorship level only allows for %s words." % self.max_words)
|
if self.max_words and num_words > self.max_words:
|
||||||
|
raise ValidationError(
|
||||||
|
"Sponsorship level only allows for %s words, you provided %d." % (
|
||||||
|
self.max_words, num_words))
|
||||||
|
|
||||||
def data_fields(self):
|
def data_fields(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue