1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[3.2.x] Fixed #32332 -- Fixed loss of parent with non-numeric pk when saving child after parent.

Follow up to 519016e5f2.

Backport of 7cba92ec55 from master
This commit is contained in:
Hasan Ramezani
2021-02-02 17:58:04 +01:00
committed by Mariusz Felisiak
parent 7d65889345
commit b36beec208
3 changed files with 22 additions and 4 deletions

View File

@@ -68,6 +68,10 @@ class Parent(models.Model):
bestchild = models.ForeignKey('Child', models.SET_NULL, null=True, related_name='favored_by')
class ParentStringPrimaryKey(models.Model):
name = models.CharField(primary_key=True, max_length=15)
class Child(models.Model):
name = models.CharField(max_length=20)
parent = models.ForeignKey(Parent, models.CASCADE)
@@ -77,6 +81,10 @@ class ChildNullableParent(models.Model):
parent = models.ForeignKey(Parent, models.CASCADE, null=True)
class ChildStringPrimaryKeyParent(models.Model):
parent = models.ForeignKey(ParentStringPrimaryKey, on_delete=models.CASCADE)
class ToFieldChild(models.Model):
parent = models.ForeignKey(Parent, models.CASCADE, to_field='name', related_name='to_field_children')