Created
March 7, 2012 14:50
-
-
Save dokterbob/1993603 to your computer and use it in GitHub Desktop.
Default validator
This file contains hidden or 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
| from django.core.exceptions import ValidationError | |
| ... | |
| def default_validator(value): | |
| """ Make sure only one instance of MyModel has default=True """ | |
| if value and MyModel.objects.filter(default=True).exists(): | |
| raise ValidationError('A default has already been defined.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment