mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
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. 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
0b120f5d64
commit
03d0f12c82
@@ -338,6 +338,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
|
||||
@@ -615,12 +633,26 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user