Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Audit filters may be used in the Django Admin to create list filters using the full name of the user.
4"""
6# Imports
8from django.contrib import admin
9from django.contrib.auth import get_user_model
10from django.utils.translation import ugettext_lazy as _
11from superdjango.conf import SUPERDJANGO
12from superdjango.shortcuts import get_user_name
14UserModel = get_user_model()
16# Exports
18__all__ = (
19 "ArchivedByListFilter",
20)
22# List Filters
25class ArchivedByListFilter(admin.SimpleListFilter):
26 """Filter for ``archived_by``.
28 **Order By**
30 Ordering for the lookup defaults to ``USERNAME_FIELD``. You can change this by setting
31 ``SUPERDJANGO_ORDER_USERS_BY`` in your ``settings.py`` file.
33 """
34 title = _("Archived By")
35 parameter_name = "archived_by"
37 def lookups(self, request, model_admin):
39 qs = UserModel.objects.all().order_by(SUPERDJANGO.USER_ORDER_USERS_BY)
41 a = list()
42 for user in qs:
43 a.append((user.pk, get_user_name(user)))
45 return a
47 def queryset(self, request, queryset):
48 lookup = "%s__pk" % self.parameter_name
49 criteria = {lookup: self.value()}
51 if self.value() is not None:
52 return queryset.filter(**criteria)