admin.py 1020 Bytes
Newer Older
1 2 3 4
"""
go/admin.py
"""

5
# Future Imports
David Haynes's avatar
David Haynes committed
6 7
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
8

9
# Django Imports
10
from django.contrib import admin
11 12
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
David Haynes's avatar
David Haynes committed
13

14
# App Imports
15
from .models import URL, RegisteredUser
16

17
class URLAdmin(admin.ModelAdmin):
18
    """
David Haynes's avatar
David Haynes committed
19
    Define what attributes display in the URL Admin
20 21
    """

22 23
    list_display = ("target", "short", "owner", "clicks", "date_created", "expires")

David Haynes's avatar
David Haynes committed
24 25 26
# Register URLAdmin
admin.site.register(URL, URLAdmin)

27
class RegisteredUserInline(admin.StackedInline):
28
    """
David Haynes's avatar
David Haynes committed
29
    Define an inline admin descriptor for User model
30 31
    """

David Haynes's avatar
David Haynes committed
32 33
    model = RegisteredUser
    can_delete = False
34

35
class UserAdmin(UserAdmin):
36
    """
David Haynes's avatar
David Haynes committed
37
    Define a new User admin
38 39
    """

David Haynes's avatar
David Haynes committed
40 41
    # see above class that we defined
    inlines = (RegisteredUserInline, )
42

David Haynes's avatar
David Haynes committed
43
# and modify User to use our new UserAdmin
44 45
admin.site.unregister(User)
admin.site.register(User, UserAdmin)