Answer the question
In order to leave comments, you need to log in
How to make lazy data fetch for form field in admin panel?
There is a ready-made project that has been developing for quite a long time.
And during the development, something like this type of construction appeared in admin.py
class FromCityToCountryDescription_Form(forms.ModelForm):
from_city = forms.ModelChoiceField(
queryset=City.objects.filter(id__in=[i.city.id for i in FlyFromCity.objects.all()]),
label=capfirst(_('fly from city'))
)
django.db.utils.OperationalError: no such table: burning_tours_flyfromcity
Answer the question
In order to leave comments, you need to log in
City.objects.filter(id__in=[i.city.id for i in FlyFromCity.objects.all()])
City.objects.filter(id__in=FlyFromCity.objects.values_list('city_id', flat=True))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question