Verified Commit da1fc5f8 authored by David Haynes's avatar David Haynes 🙆
Browse files

Cleanup of admin.py plus some comments (Closes #38)

- starting the commenting process
- cleanup = removing stuff that doesn't actually do anything
parent a8c80d79
"""
Django admin interface configuration.
https://docs.djangoproject.com/en/1.11/ref/contrib/admin/
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -8,46 +13,48 @@ from django.contrib import admin
# App Imports
from .models import Facility, Schedule, OpenTime, Category, Location
class OpenTimeInline(admin.TabularInline):
model = OpenTime
fk_name = 'schedule'
max_num = 7
class OpenTimeAdmin(admin.ModelAdmin):
pass
class FacilityAdmin(admin.ModelAdmin):
"""
"""
model = Facility
list_display = ['name', ]
list_filter = ['facility_category', 'facility_location']
fieldsets = (
(None, {
'fields': ('name', 'facility_category', 'facility_location',
'main_schedule', 'special_schedules', ),
}),
('Advanced', {
'fields': ('owners', ),
'classes': ('collapse', ),
'main_schedule', 'special_schedules', 'owners'),
}),
)
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
class ScheduleAdmin(admin.ModelAdmin):
"""
"""
list_display = ['name', 'modified']
inlines = [OpenTimeInline, ]
fieldsets = (
(None, {
# (name, (start, end))
'fields': ('name', ('valid_start', 'valid_end'))
'fields': ('name',
# Pair valid_start and valid_end together on the same
# line
('valid_start', 'valid_end'))
}),
)
class CategoryAdmin(admin.ModelAdmin):
pass
class LocationAdmin(admin.ModelAdmin):
pass
# Register the administration panels
# https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects
admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Location, LocationAdmin)
# Use the default ModelAdmin interface for these
admin.site.register(Category)
admin.site.register(Location)
......@@ -19,7 +19,7 @@ class Category(TimeStampedModel):
class Meta:
verbose_name = "category"
verbose_name_plural = "categories"
# Sort by name in admin view
# Sort by name in admin view.
ordering = ['name']
def __str__(self):
......@@ -27,16 +27,27 @@ class Category(TimeStampedModel):
class Location(TimeStampedModel):
"""
Represents a specific location (unique lat, lon) that a Facility can be
found in real life.
Represents a specific location that a Facility can be found.
"""
# The building that the facility is located in (on campus)
building = models.CharField(max_length=100, null=True, blank=True)
# The physical address of the facility
address = models.CharField(max_length=100, null=True, blank=True)
# Boolean for whether or not the location is "on campus" or not
# The building that the facility is located in (on campus).
building = models.CharField(max_length=100)
# The physical address of the facility.
address = models.CharField(max_length=100)
# Boolean for whether or not the location is "on campus" or not.
on_campus = models.BooleanField(default=True)
class Meta:
verbose_name = "location"
verbose_name_plural = "locations"
def __str__(self):
"""
String representation of a Location object.
"""
return 'Found in %s at %s | On Campus: %s' % (self.building,
self.address,
self.on_campus)
class Facility(TimeStampedModel):
"""
Represents a specific facility location.
......
"""
Rest Framework Serializers
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -8,26 +11,25 @@ from .models import Category, Facility, Schedule, OpenTime, Location
# Other Imports
from rest_framework import serializers
class CategorySerializer(serializers.ModelSerializer):
class OpenTimeSerializer(serializers.ModelSerializer):
"""
"""
class Meta:
model = Category
model = OpenTime
fields = '__all__'
class LocationSerializer(serializers.ModelSerializer):
class CategorySerializer(serializers.ModelSerializer):
"""
"""
class Meta:
model = Location
model = Category
fields = '__all__'
class OpenTimeSerializer(serializers.ModelSerializer):
class LocationSerializer(serializers.ModelSerializer):
"""
"""
class Meta:
model = OpenTime
model = Location
fields = '__all__'
class ScheduleSerializer(serializers.ModelSerializer):
......@@ -50,5 +52,5 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Facility
fields = ('id', 'facility_category', 'facility_location', 'main_schedule',
'special_schedules', 'modified', 'name')
fields = ('id', 'facility_category', 'facility_location',
'main_schedule', 'special_schedules', 'modified', 'name')
......@@ -7,7 +7,8 @@ from django.conf.urls import include, url
from django.views.generic.base import RedirectView
# App Imports
from .views import CategoryViewSet, FacilityViewSet, ScheduleViewSet, LocationViewSet
from .views import (CategoryViewSet, FacilityViewSet, ScheduleViewSet,
LocationViewSet)
# Other Imports
from rest_framework.routers import DefaultRouter
......@@ -19,7 +20,7 @@ ROUTER = DefaultRouter()
ROUTER.register(r'categories', CategoryViewSet)
ROUTER.register(r'facilities', FacilityViewSet)
ROUTER.register(r'schedules', ScheduleViewSet)
ROUTER.register(r'location', LocationViewSet)
ROUTER.register(r'locations', LocationViewSet)
urlpatterns = [
# / - Default route
......
"""
Rest Framework Class Views
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -5,12 +8,12 @@ from __future__ import (absolute_import, division, print_function,
# App Imports
from .models import Facility, OpenTime, Category, Schedule, Location
from .serializers import (CategorySerializer, FacilitySerializer,
ScheduleSerializer, OpenTimeSerializer, LocationSerializer)
ScheduleSerializer, OpenTimeSerializer,
LocationSerializer)
# Other Imports
from rest_framework import viewsets
# Rest Framework Class Views
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
"""
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment