I have in my models.py
class Business(models.Model):
industry = models.models.ManyToManyField(Industry)
in forms.py
class BusinessForm(forms.ModelForm):
class Meta:
model = Business
When I render the form, the industry names appear in a multiple select box. What do I do to make the industry names in alphabetical order?
There are several ways:
You can override the queryset ordering on a per-form basis, set the ordering meta class option, or override the model manager queryset with an ordering method.
Override global model manager queryset
Specify global meta option ordering
Per form ordering
There’s also a shortcut called formfield_for_manytomany if you are dealing with the django admin.