Answer the question
In order to leave comments, you need to log in
Sorting queryset?
There is a ModelForm with a ModelChoiceField(queryset=Country.objects.all().order_by("name")) The countries are selected in the select, you need to move the Russia element to the very beginning of the option list, but at the same time keep the sorting, is it possible do in the form? or better through js?
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/1336900/django-modelch...
class YourForm(forms.Form):
field1 = forms.ModelChoiceField(queryset = MyModel.objects.all() )
form = YourForm(initial = {'field1': instance_of_mymodel.pk })
queryset=[
Country.objects.filter(name="Russia"),
Country.objects.exclude(name="Russia").order_by("name")]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question