Answer the question
In order to leave comments, you need to log in
How to sort option in select in django?
How can sort before output in select option in django?
I have two tables with categories (which is created by the user himself) and articles. And when adding to the form, it is necessary that the categories in the form of options are displayed in the select, only those that the user himself created.
I tried to draw output through for, but the problem is that I don't know how to save it to the database.
Answer the question
In order to leave comments, you need to log in
How to sort option in select on django
it is necessary that the categories in the form of options would be displayed in the select, only those that the user himself created.
self.fields['category'].queryset = Category.objects.filter(user=user)
in the modelform, in the select field, set the queriset with the desired filter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question