mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #26291 -- Allowed loaddata to handle forward references in natural_key fixtures.
This commit is contained in:
parent
8f75d21a2e
commit
312eb5cb11
12 changed files with 352 additions and 25 deletions
|
@ -19,3 +19,21 @@ class NaturalKeyAnchor(models.Model):
|
|||
|
||||
class FKDataNaturalKey(models.Model):
|
||||
data = models.ForeignKey(NaturalKeyAnchor, models.SET_NULL, null=True)
|
||||
|
||||
|
||||
class NaturalKeyThing(models.Model):
|
||||
key = models.CharField(max_length=100)
|
||||
other_thing = models.ForeignKey('NaturalKeyThing', on_delete=models.CASCADE, null=True)
|
||||
other_things = models.ManyToManyField('NaturalKeyThing', related_name='thing_m2m_set')
|
||||
|
||||
class Manager(models.Manager):
|
||||
def get_by_natural_key(self, key):
|
||||
return self.get(key=key)
|
||||
|
||||
objects = Manager()
|
||||
|
||||
def natural_key(self):
|
||||
return (self.key,)
|
||||
|
||||
def __str__(self):
|
||||
return self.key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue