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

5
# Django Imports
6
from django.contrib import admin
7
8
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
David Haynes's avatar
David Haynes committed
9

10
# App Imports
11
from .models import URL, RegisteredUser
12

13
class URLAdmin(admin.ModelAdmin):
14
    """
David Haynes's avatar
David Haynes committed
15
    Define what attributes display in the URL Admin
16
17
    """

18
19
    list_display = ("target", "short", "owner", "clicks", "date_created", "expires")

David Haynes's avatar
David Haynes committed
20
21
22
# Register URLAdmin
admin.site.register(URL, URLAdmin)

23
class RegisteredUserInline(admin.StackedInline):
24
    """
David Haynes's avatar
David Haynes committed
25
    Define an inline admin descriptor for User model
26
27
    """

David Haynes's avatar
David Haynes committed
28
29
    model = RegisteredUser
    can_delete = False
30

31
class UserAdmin(UserAdmin):
32
    """
David Haynes's avatar
David Haynes committed
33
    Define a new User admin
34
35
    """

David Haynes's avatar
David Haynes committed
36
37
    # see above class that we defined
    inlines = (RegisteredUserInline, )
38

David Haynes's avatar
David Haynes committed
39
# and modify User to use our new UserAdmin
40
41
admin.site.unregister(User)
admin.site.register(User, UserAdmin)