Skip to content

Instantly share code, notes, and snippets.

@dokterbob
Created March 7, 2012 14:50
Show Gist options
  • Select an option

  • Save dokterbob/1993603 to your computer and use it in GitHub Desktop.

Select an option

Save dokterbob/1993603 to your computer and use it in GitHub Desktop.
Default validator
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