Last active
December 16, 2015 23:29
-
-
Save ekinertac/5514627 to your computer and use it in GitHub Desktop.
Django: Validate Model Instance Count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_count(obj): | |
model = obj.__class__ | |
if model.objects.count() >= 8: | |
raise ValidationError('You can add only 8 slider objects %s' % model.__name__) | |
class Slider(models.Model): | |
# Model fields | |
def clean(self): | |
validate_count(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment