django-modeltranslation icon indicating copy to clipboard operation
django-modeltranslation copied to clipboard

Referenced models from forms aren't ordered using the active language

Open caumons opened this issue 11 years ago • 2 comments

ModelForms referencing other Models through ForeignKey or ManyToManyField that have the field ordering in their Meta classes aren't ordered based on the active language. However, if you go to the admin, for example, and see the list of each of the referenced models, then the lists are well ordered based on the active language.

caumons avatar Oct 21 '13 15:10 caumons

I don't know if there is a better solution, but I found a workaround, modifying the field's queryset from inside the form constructor (__init__ method). For example:

class FooForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(FooForm, self).__init__(*args, **kwargs)
        self.fields['category'].queryset = Category.objects.order_by('name')

caumons avatar Nov 09 '13 14:11 caumons

Thanks for the workaround!

Lauriy avatar Nov 21 '15 15:11 Lauriy