diff options
author | Johannes Maron <info@johanneshoppe.com> | 2021-03-18 11:21:23 +0100 |
---|---|---|
committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-03-18 11:21:23 +0100 |
commit | 03d0f12c823239812da21e5180aaa74dc6fd146e (patch) | |
tree | 90aeb14f7d703b552c7ab645dbd82f08960189a4 /tests/admin_views/models.py | |
parent | 0b120f5d649fb21bb898a8b834b6b33e4cdd9504 (diff) | |
download | django-03d0f12c823239812da21e5180aaa74dc6fd146e.tar.gz |
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>
Diffstat (limited to 'tests/admin_views/models.py')
-rw-r--r-- | tests/admin_views/models.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py index 4ab2bc8eee..284a4cfacb 100644 --- a/tests/admin_views/models.py +++ b/tests/admin_views/models.py @@ -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) |