Enforced uniqueness of natural keys used in tests.
This commit is contained in:
parent
678f958ef9
commit
cf21fc9bf0
|
@ -66,7 +66,7 @@ class PersonManager(models.Manager):
|
|||
|
||||
class Person(models.Model):
|
||||
objects = PersonManager()
|
||||
name = models.CharField(max_length=100)
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
@ -119,7 +119,7 @@ class PrimaryKeyUUIDModel(models.Model):
|
|||
|
||||
|
||||
class NaturalKeyThing(models.Model):
|
||||
key = models.CharField(max_length=100)
|
||||
key = models.CharField(max_length=100, unique=True)
|
||||
other_thing = models.ForeignKey('NaturalKeyThing', on_delete=models.CASCADE, null=True)
|
||||
other_things = models.ManyToManyField('NaturalKeyThing', related_name='thing_m2m_set')
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class TestManager(models.Manager):
|
|||
|
||||
|
||||
class Store(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
main = models.ForeignKey('self', models.SET_NULL, null=True)
|
||||
|
||||
objects = TestManager()
|
||||
|
@ -114,7 +114,7 @@ class Store(models.Model):
|
|||
|
||||
|
||||
class Person(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
objects = TestManager()
|
||||
|
||||
|
@ -178,7 +178,7 @@ class RefToNKChild(models.Model):
|
|||
|
||||
# ome models with pathological circular dependencies
|
||||
class Circle1(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -186,7 +186,7 @@ class Circle1(models.Model):
|
|||
|
||||
|
||||
class Circle2(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -194,7 +194,7 @@ class Circle2(models.Model):
|
|||
|
||||
|
||||
class Circle3(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -202,7 +202,7 @@ class Circle3(models.Model):
|
|||
|
||||
|
||||
class Circle4(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -210,7 +210,7 @@ class Circle4(models.Model):
|
|||
|
||||
|
||||
class Circle5(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -218,7 +218,7 @@ class Circle5(models.Model):
|
|||
|
||||
|
||||
class Circle6(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
@ -226,7 +226,7 @@ class Circle6(models.Model):
|
|||
|
||||
|
||||
class ExternalDependency(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name,)
|
||||
|
|
|
@ -25,7 +25,7 @@ class PersonManager(models.Manager):
|
|||
|
||||
|
||||
class Person(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
|
||||
objects = PersonManager()
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class FKDataNaturalKey(models.Model):
|
|||
|
||||
|
||||
class NaturalKeyThing(models.Model):
|
||||
key = models.CharField(max_length=100)
|
||||
key = models.CharField(max_length=100, unique=True)
|
||||
other_thing = models.ForeignKey('NaturalKeyThing', on_delete=models.CASCADE, null=True)
|
||||
other_things = models.ManyToManyField('NaturalKeyThing', related_name='thing_m2m_set')
|
||||
|
||||
|
|
Loading…
Reference in New Issue