django-admin

In Django admin, how to filter users by group?

半城伤御伤魂 提交于 2020-12-01 10:41:25
问题 It gives you filter by staff status and superuser status, but what about groups? 回答1: Since version 1.3 it can be done using this: list_filter = ('groups__name') Of course as @S.Lott explains you must register your customized class in the admin.py file: from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User class MyUserAdmin(UserAdmin): list_filter = UserAdmin.list_filter + ('groups__name',) admin.site.unregister(User)

Why does Django admin list_select_related not work in this case?

十年热恋 提交于 2020-11-30 06:45:10
问题 I've got a ModelAdmin class that includes a foreign key field in its list_display . But the admin list page for that model is doing hundreds of queries, one query per row to get the data from the other table instead of a join ( select_related() ). The Django docs indicate you can add list_select_related = True as an attribute to your ModelAdmin to make this go away, but it doesn't seem to work at all for me. This SO question seems to give a similar problem, but his resolution is unclear, and