So I have a ModelForm with a select field. In this select field there are about 100 entries. Of these entries I have a number of entries like "Organization Colorado - Denver", which I would like to have at the top of the list, such that all the entries with "Organization Colorado" are at the top of the list, and everything else is sorted in lexicographical order.
I've tried making two separate querysets (this seems like a bad idea, but manageable with only 100 or so entries). There seems to be a lot of ways of combining these two query sets, but without maintaining the order (which is the point). I've tried this:
class CreateContactForm(ModelForm):
...
def __init__(self, *args, **kwargs):
super(CreateContactForm, self).__init__(*args, **kwargs)
p = models.ConstantContactList.objects.filter(
name__startswith=settings.PREF_ORGANIZATION_PREFIX
)
np = models.ConstantContactList.objects.filter(
name__regex=r'^(?!{})'.format(settings.PREF_ORGANIZATION_PREFIX)
).order_by('-name')
self.fields['cc_lists'].queryset = list(p) + list(np)
This doesn't work, although it might, if there was some way to convert that list back into a queryset, or if there is a way to go around the queryset maybe? I'm not sure. Can anyone provide a clue as to what I should do?