admin.py 1.16 KB
Newer Older
luxcem's avatar
luxcem committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User, Permission
from django.utils.translation import ugettext_lazy as _

from userprofile.models import Profile


@admin.register(Permission)
class PermissionAdmin(admin.ModelAdmin):
    list_display = ("name", "codename", "content_type")
    list_filter = ("content_type",)


class UserProfileInline(admin.StackedInline):
    model = Profile
    list_display = ("user", "full_name")

    extra = 1
    max_num = 1


class UserProfileAdmin(UserAdmin):
    inlines = [UserProfileInline]
25 26 27

    list_display = ("username", "email", "first_name", "last_name", "is_staff", "get_groups")

luxcem's avatar
luxcem committed
28 29 30 31
    fieldsets = (
        (None, {"fields": ("username", "password")}),
        (_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
        (_("Permissions"), {
32
            "fields": ("is_active", "is_staff", "is_superuser", "groups")}),
luxcem's avatar
luxcem committed
33 34
    )

35 36 37
    def get_groups(self, obj):
        return ", ".join(sorted([g.name for g in obj.groups.all()]))
    get_groups.short_description = _("Groups")
luxcem's avatar
luxcem committed
38 39 40

admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)