admin.py 1.77 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
14
15

# App Imports
David Haynes's avatar
David Haynes committed
16
from .models import Facility, Schedule, OpenTime, Category, Location
17

Ben Waters's avatar
Ben Waters committed
18
class FacilityAdmin(admin.ModelAdmin):
19
20
    """
    """
21
    model = Facility
David Haynes's avatar
David Haynes committed
22
23
    list_display = ['name', ]
    list_filter = ['facility_category', 'facility_location']
24
25
    fieldsets = (
        (None, {
David Haynes's avatar
David Haynes committed
26
            'fields': ('name', 'facility_category', 'facility_location',
27
                       'main_schedule', 'special_schedules', 'owners'),
28
        }),
29
    )
30

31
32
33
34
35
36
37
38
39
40
41
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

42
class ScheduleAdmin(admin.ModelAdmin):
43
44
    """
    """
45
    list_display = ['name', 'modified']
46
    inlines = [OpenTimeInline, ]
47
48
    fieldsets = (
        (None, {
49
50
51
52
            'fields': ('name',
                       # Pair valid_start and valid_end together on the same
                       # line
                       ('valid_start', 'valid_end'))
David Haynes's avatar
David Haynes committed
53
        }),
54
    )
55

56
57
# Register the administration panels
# https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects
Ben Waters's avatar
Ben Waters committed
58
admin.site.register(Facility, FacilityAdmin)
59
admin.site.register(Schedule, ScheduleAdmin)
60
61
62
# Use the default ModelAdmin interface for these
admin.site.register(Category)
admin.site.register(Location)