Skip to content

Instantly share code, notes, and snippets.

@alexander-arce
Created May 9, 2014 14:47
Show Gist options
  • Save alexander-arce/9e791736f6660e4f9733 to your computer and use it in GitHub Desktop.
Save alexander-arce/9e791736f6660e4f9733 to your computer and use it in GitHub Desktop.
Override field propierties on inherited model in Django
from django.contrib.sites.models import Site as SiteOld
class Site(SiteOld):
"""Site only have a one Costumer/Shop."""
costumer = models.OneToOneField('Costumer', verbose_name='customer')
def __init__(self, *args, **kwargs):
"""
Overrided __init__.
Set unique constraints for domain and name fields
Check in case of unique works with '_',
but blank and null don't
"""
super(Site, self).__init__(self, *args, **kwargs)
self._meta.get_field('domain')._unique = True
self._meta.get_field('name')._unique = True
self._meta.get_field('name').blank = False
self._meta.get_field('name').null = False
class Meta:
verbose_name = _('site costumer')
verbose_name_plural = _('sites costumers')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment