mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +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:
committed by
Mariusz Felisiak
parent
deedf5bbc3
commit
c72f6f36c1
@@ -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},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user