mirror of
https://github.com/django/django.git
synced 2025-10-29 08:36:09 +00:00
[3.2.x] Fixed #32466 -- Corrected autocomplete to_field resolution for complex cases.
In MTI or ForeignKey as primary key cases, it is required to fetch the attname from the field instance on the remote model in order to reliably resolve the to_field_name. Backport ofceb4b9ee68from main Backport of03d0f12c82from main Co-authored-by: Johannes Maron <info@johanneshoppe.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
This commit is contained in:
committed by
Carlton Gibson
parent
6b020f3c94
commit
a8fef6daaf
@@ -339,6 +339,24 @@ class Child(models.Model):
|
||||
raise ValidationError('invalid')
|
||||
|
||||
|
||||
class PKChild(models.Model):
|
||||
"""
|
||||
Used to check autocomplete to_field resolution when ForeignKey is PK.
|
||||
"""
|
||||
parent = models.ForeignKey(Parent, models.CASCADE, primary_key=True)
|
||||
name = models.CharField(max_length=128)
|
||||
|
||||
class Meta:
|
||||
ordering = ['parent']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Toy(models.Model):
|
||||
child = models.ForeignKey(PKChild, models.CASCADE)
|
||||
|
||||
|
||||
class EmptyModel(models.Model):
|
||||
def __str__(self):
|
||||
return "Primary key = %s" % self.id
|
||||
@@ -617,13 +635,28 @@ class Song(models.Model):
|
||||
class Employee(Person):
|
||||
code = models.CharField(max_length=20)
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
|
||||
class WorkHour(models.Model):
|
||||
datum = models.DateField()
|
||||
employee = models.ForeignKey(Employee, models.CASCADE)
|
||||
|
||||
|
||||
class Manager(Employee):
|
||||
"""
|
||||
A multi-layer MTI child.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Bonus(models.Model):
|
||||
recipient = models.ForeignKey(Manager, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class Question(models.Model):
|
||||
big_id = models.BigAutoField(primary_key=True)
|
||||
question = models.CharField(max_length=20)
|
||||
posted = models.DateField(default=datetime.date.today)
|
||||
expires = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
Reference in New Issue
Block a user