SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class SrdObject(models.Model):
  2.     name = models.CharField(max_length=50)
  3.     slug_name = models.SlugField(max_length=75, unique=True)
  4.     active = models.BooleanField(default=True)
  5.     module = models.ForeignKey(Module, on_delete=models.CASCADE, related_name='%(class)s', blank=False, null=False, default='default')
  6.  
  7.     class Meta:
  8.         unique_together = ['name', 'module']
  9.         ordering = ['name']
  10.         abstract = True
  11.      
  12. class Meta:
  13.     constraints = [
  14.         models.UniqueConstraint(fields=['name', 'module'], name='unique-in-module')
  15.     ]
  16.     ordering = ['name']
  17.     abstract = True
  18.      
  19. models.UniqueConstraint(fields=['name', 'module'], name='{}-unique-in-module'.format(model_name))
  20.      
  21. def add_unique_in_module_constraint(cls):
  22.     cls._meta.constraints = [
  23.         models.UniqueConstraint(fields=['name', 'module'], name='unique-in-module')
  24.     ]
  25.     return cls
  26.  
  27. @add_unique_in_module_constraint
  28. class SrdObject(models.Model):
  29.     class Meta:
  30.         ordering = ['name']
  31.         abstract = True
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top