admin.py 2.69 KB
Newer Older
1
"""
2
3
api/admin.py

4
5
6
7
Django admin interface configuration.

https://docs.djangoproject.com/en/1.11/ref/contrib/admin/
"""
8
9
10
11
12
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# Django Imports
13
from django.contrib import admin
David Haynes's avatar
David Haynes committed
14
from django.contrib.gis.admin import OSMGeoAdmin
15
# App Imports
David Haynes's avatar
David Haynes committed
16
from .models import Facility, Schedule, OpenTime, Category, Location, Alert
17

Ben Waters's avatar
Ben Waters committed
18
class FacilityAdmin(admin.ModelAdmin):
19
    """
David Haynes's avatar
David Haynes committed
20
21
22
    Custom Admin panel for the Facility model.

    Allows admins to create new facilities through the admin interface.
23
    """
David Haynes's avatar
David Haynes committed
24
    # Allow filtering by the following fields
David Haynes's avatar
David Haynes committed
25
    list_filter = ['facility_category', 'facility_location']
David Haynes's avatar
David Haynes committed
26
27
    # Modify the rendered layout of the "create a new facility" page
    # We are basically reordering things to look nicer to the user here
28
29
    fieldsets = (
        (None, {
David Haynes's avatar
David Haynes committed
30
            'fields': ('facility_name', 'facility_category', 'facility_location',
31
32
                       'main_schedule', 'special_schedules', 
                       'facility_product_tags', 'tapingo_url', 'owners'),
33
        }),
34
    )
35

36
37
38
39
40
41
42
43
44
45
46
class OpenTimeInline(admin.TabularInline):
    """
    A table of time periods that represent an "open time" for a Facility.

    https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.TabularInline
    """
    # Columns correspond to each attribute in the OpenTime table
    model = OpenTime
    # 7 days of the week, so only have 7 rows
    max_num = 7

47
class ScheduleAdmin(admin.ModelAdmin):
48
    """
David Haynes's avatar
David Haynes committed
49
50
51
52
53
    Custom Admin panel for the Schedule model.

    Allows admins to create new schedules through the admin interface.
    Additionally, we append the OpenTimeInline table to allow for open times to
    be defined for the schedule we are creating.
54
    """
David Haynes's avatar
David Haynes committed
55
    # Allow filtering by the following fields
56
    list_display = ['name', 'modified']
David Haynes's avatar
David Haynes committed
57
    # Append the OpenTimeInline table to the end of our admin panel
58
    inlines = [OpenTimeInline, ]
David Haynes's avatar
David Haynes committed
59
    # Modify the rendered layout of the "create a new facility" page
60
61
    fieldsets = (
        (None, {
62
63
64
65
            'fields': ('name',
                       # Pair valid_start and valid_end together on the same
                       # line
                       ('valid_start', 'valid_end'))
David Haynes's avatar
David Haynes committed
66
        }),
67
    )
68

David Haynes's avatar
David Haynes committed
69
# Register the custom administration panels
70
# https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects
Ben Waters's avatar
Ben Waters committed
71
admin.site.register(Facility, FacilityAdmin)
72
admin.site.register(Schedule, ScheduleAdmin)
David Haynes's avatar
David Haynes committed
73
74
# https://docs.djangoproject.com/en/1.11/ref/contrib/gis/admin/#osmgeoadmin
admin.site.register(Location, OSMGeoAdmin)
75
76
# Use the default ModelAdmin interface for these
admin.site.register(Category)
David Haynes's avatar
David Haynes committed
77
admin.site.register(Alert)