how can I change the order of the values in the ModelChoiceField billing_company?
models.py
class Company(models.Model):
name = models.CharField(max_length=30, unique=True)
forms.py
billing_company = forms.ModelChoiceField(Company.objects, required=True)
Thanks for your help. Tom
ModelChoiceField
takes a QuerySet as its first parameter, so you should be able to pass an ordered set:
forms.ModelChoiceField(Company.objects.order_by('-pk'), required=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With