admin.py 1.18 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

Okhin's avatar
Okhin committed
26 27
    list_display = ("username", "email", "first_name", "last_name",
                    "is_staff", "get_groups")
28

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

36 37 38
    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
39

Okhin's avatar
Okhin committed
40

luxcem's avatar
luxcem committed
41 42
admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)