summaryrefslogtreecommitdiff
path: root/tests/admin_widgets/models.py
diff options
context:
space:
mode:
authorJohannes Maron <info@johanneshoppe.com>2021-03-18 11:21:23 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-03-18 14:21:12 +0100
commita8fef6daaf75cd24262d973b154fb6580efd99a4 (patch)
treee70b7be0a7e5fd69f2edef03787dab806c1bde4d /tests/admin_widgets/models.py
parent6b020f3c94fb7f27875d5fe21a71a5ee7c9a7538 (diff)
[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 of ceb4b9ee68dffc6ab0398886f1758f15f037c472 from main Backport of 03d0f12c823239812da21e5180aaa74dc6fd146e from 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>
Diffstat (limited to 'tests/admin_widgets/models.py')
-rw-r--r--tests/admin_widgets/models.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/admin_widgets/models.py b/tests/admin_widgets/models.py
index 85f71749fd..85ba6c4f36 100644
--- a/tests/admin_widgets/models.py
+++ b/tests/admin_widgets/models.py
@@ -18,7 +18,11 @@ class Member(models.Model):
return self.name
-class Band(models.Model):
+class Artist(models.Model):
+ pass
+
+
+class Band(Artist):
uuid = models.UUIDField(unique=True, default=uuid.uuid4)
name = models.CharField(max_length=100)
style = models.CharField(max_length=20)
@@ -47,6 +51,25 @@ class Album(models.Model):
return self.name
+class ReleaseEvent(models.Model):
+ """
+ Used to check that autocomplete widget correctly resolves attname for FK as
+ PK example.
+ """
+ album = models.ForeignKey(Album, models.CASCADE, primary_key=True)
+ name = models.CharField(max_length=100)
+
+ class Meta:
+ ordering = ['name']
+
+ def __str__(self):
+ return self.name
+
+
+class VideoStream(models.Model):
+ release_event = models.ForeignKey(ReleaseEvent, models.CASCADE)
+
+
class HiddenInventoryManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(hidden=False)