1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +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:
Johannes Maron
2021-03-18 11:21:23 +01:00
committed by Carlton Gibson
parent 0b120f5d64
commit 03d0f12c82
8 changed files with 153 additions and 8 deletions

View File

@@ -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)