Advertisement
ep123pearce

Admin

Jan 7th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. from .models import Profile, Question
  2. from django.contrib import admin
  3. from django.contrib.auth.admin import UserAdmin
  4. from django.contrib.auth.models import User
  5.  
  6. from .models import Profile
  7.  
  8. class ProfileInline(admin.StackedInline):
  9. model = Profile
  10. can_delete = False
  11. verbose_name_plural = 'Profile'
  12. fk_name = 'user'
  13.  
  14.  
  15. class CustomUserAdmin(UserAdmin):
  16. inlines = (ProfileInline, )
  17. list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'get_location')
  18. list_select_related = ('profile', )
  19.  
  20. def get_location(self, instance):
  21. return instance.profile.location
  22. get_location.short_description = 'Location'
  23.  
  24. def get_inline_instances(self, request, obj=None):
  25. if not obj:
  26. return list()
  27. return super(CustomUserAdmin, self).get_inline_instances(request, obj)
  28.  
  29.  
  30. admin.site.unregister(User)
  31. admin.site.register(User, CustomUserAdmin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement