2👍
Does contact_country = forms.ModelChoiceField(queryset=Country.objects.order_by('special'))
work?
0👍
This is untested, so you may give it a try, but it may not give it what you want…
in your view do this:
specials = Country.objects.filter(special=True)
all_of = Country.objects.all()
# worst thing is, this is a list, not a queryset...
new_list = list(specials)+list(all_of)
# add new object to you form...
YourForm.base_fields['contact_country'] = forms.ChoiceField(choices=[(x.id,x) for x in new_list])
Your handicap is, yo create the list using a list, not directly from queryset
This will solve your pronblem, with a dirty looking way, but it is a solution i used when modelform can not help you…
- [Answered ]-Django admin page adding save as pdf button
- [Answered ]-Using context variables inside text inside template tag in django
- [Answered ]-Django south cannot import required field
- [Answered ]-Django-redis configuration to use socket rather than TCP
- [Answered ]-Trouble with list_display in django. Possibly ForeignKey issue?
0👍
You can override the default ordering:
class Meta:
ordering = [ '-special', 'printable_name' ]
You can also write a custom manager but it doesn’t worth…
👤Don
- [Answered ]-How to get username of request from ModelViewSet class in Django rest API?
- [Answered ]-How to access parent abstract class of model in Django
- [Answered ]-Django templates, including page(s) that injects code into parent block
- [Answered ]-Running two Django Apps on Apache with mod_auth_sspi and mod_wsgi
- [Answered ]-Unsure how to correctly use Django models for a relationship with extra info
Source:stackexchange.com