admin.py 1.76 KB
Newer Older
1
2
3
4
5
"""
Django admin interface configuration.

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

# Django Imports
11
from django.contrib import admin
12
13

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

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

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

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

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