Enforced uniqueness of natural keys used in tests.

This commit is contained in:
Mariusz Felisiak 2020-04-07 10:54:19 +02:00 committed by GitHub
parent 678f958ef9
commit cf21fc9bf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View File

@ -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')

View File

@ -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,)

View File

@ -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()

View File

@ -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')