7
7
7761662017-08-28 21:46:24
Django
776166, 2017-08-28 21:46:24

How in django admin to sort fields in a dropdown list editor?

There is a model in which there is a field of type models.ForeignKey.
In the editor, this field is rendered as a drop-down list with incomprehensible sorting. How to sort it properly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Kuzmichev, 2017-08-28
@776166

Look at 2 top answers, they describe 2 possible ways to solve your problem.
https://stackoverflow.com/questions/18742632/how-t...

  1. Set Meta.orderingon the model referenced by your foreign key
  2. Override the method formfield_for_foreignkeyin your model's admin class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question