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# Imports
3from django.contrib import admin
4from django.utils.translation import ugettext_lazy as _
5from .filters import OwnedByListFilter
7# Exports
9__all__ = (
10 "BaseOwnedByAdmin",
11)
13# Models
16class BaseOwnedByAdmin(admin.ModelAdmin):
17 """Base admin class for models implementing the ``OwnedByModel``."""
19 def get_actions(self, request):
20 return [
21 "set_current_owner",
22 ]
24 def get_fields(self, request, obj=None):
25 return [
26 "owned_by",
27 ]
29 def get_list_display(self, request):
30 return [
31 "owned_by",
32 ]
34 def get_list_filter(self, request):
35 return [
36 OwnedByListFilter,
37 ]
39 def set_current_owner(self, request, queryset):
40 """Set record ownership to the current user."""
41 count = 0
42 for row in queryset:
43 row.owned_by = request.user
44 row.save()
45 count += 1
47 self.message_user(request, _("Changed ownership of %s records." % count))
49 set_current_owner.short_description = _("Set Yourself as the Owner of the Select Records")