Hide keyboard shortcuts

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 

2 

3from django.contrib import admin 

4from django.utils.translation import ugettext_lazy as _ 

5from .filters import OwnedByListFilter 

6 

7# Exports 

8 

9__all__ = ( 

10 "BaseOwnedByAdmin", 

11) 

12 

13# Models 

14 

15 

16class BaseOwnedByAdmin(admin.ModelAdmin): 

17 """Base admin class for models implementing the ``OwnedByModel``.""" 

18 

19 def get_actions(self, request): 

20 return [ 

21 "set_current_owner", 

22 ] 

23 

24 def get_fields(self, request, obj=None): 

25 return [ 

26 "owned_by", 

27 ] 

28 

29 def get_list_display(self, request): 

30 return [ 

31 "owned_by", 

32 ] 

33 

34 def get_list_filter(self, request): 

35 return [ 

36 OwnedByListFilter, 

37 ] 

38 

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 

46 

47 self.message_user(request, _("Changed ownership of %s records." % count)) 

48 

49 set_current_owner.short_description = _("Set Yourself as the Owner of the Select Records")