1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #11803 -- Allowed admin select widgets to display new related objects.

Adjusted admin javascript to add newly created related objects to
already loaded select widgets.

In this version, applies only where limit_choices_to is not set.
This commit is contained in:
mgaligniana
2022-04-13 15:27:21 +02:00
committed by Mariusz Felisiak
parent deedf5bbc3
commit c72f6f36c1
7 changed files with 216 additions and 3 deletions

View File

@@ -1098,3 +1098,39 @@ class Box(models.Model):
next_box = models.ForeignKey(
"self", null=True, on_delete=models.SET_NULL, blank=True
)
class Country(models.Model):
NORTH_AMERICA = "North America"
SOUTH_AMERICA = "South America"
EUROPE = "Europe"
ASIA = "Asia"
OCEANIA = "Oceania"
ANTARCTICA = "Antarctica"
CONTINENT_CHOICES = [
(NORTH_AMERICA, NORTH_AMERICA),
(SOUTH_AMERICA, SOUTH_AMERICA),
(EUROPE, EUROPE),
(ASIA, ASIA),
(OCEANIA, OCEANIA),
(ANTARCTICA, ANTARCTICA),
]
name = models.CharField(max_length=80)
continent = models.CharField(max_length=13, choices=CONTINENT_CHOICES)
def __str__(self):
return self.name
class Traveler(models.Model):
born_country = models.ForeignKey(Country, models.CASCADE)
living_country = models.ForeignKey(
Country, models.CASCADE, related_name="living_country_set"
)
favorite_country_to_vacation = models.ForeignKey(
Country,
models.CASCADE,
related_name="favorite_country_to_vacation_set",
limit_choices_to={"continent": Country.ASIA},
)