How to change the Django admin filter to use a dropdown instead of list?

后端 未结 9 856
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 03:58

If, for a field that you want to filter by, you have more than ~10 values, the filtering sidebar starts to be ugly and harder to use.

I\'m looking for a solution to

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 04:16

    You can copy the admin templates from the django installation into you templates/admin folder in your project.

    Then you will need to do any of 2 things in the forms or templates you want to show your outputs in:

    1. If you are working with a form, in that you would like the list choices to be posted back to a database, you would in your model.py, on the field you have your choices, put in some this like this:

      choice = forms.IntegerField(widget=forms.Select(choices=CHOICES))
      
    2. If it is just to display on a page, then you will output on a template tag something like this:

      
      

提交回复
热议问题