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
Pipeline #1369 passed with stage
in 1 minute and 18 seconds
"""
Django admin interface configuration.
https://docs.djangoproject.com/en/1.11/ref/contrib/admin/
"""
# Future Imports # Future Imports
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
...@@ -8,46 +13,48 @@ from django.contrib import admin ...@@ -8,46 +13,48 @@ from django.contrib import admin
# App Imports # App Imports
from .models import Facility, Schedule, OpenTime, Category, Location 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): class FacilityAdmin(admin.ModelAdmin):
"""
"""
model = Facility model = Facility
list_display = ['name', ] list_display = ['name', ]
list_filter = ['facility_category', 'facility_location'] list_filter = ['facility_category', 'facility_location']
fieldsets = ( fieldsets = (
(None, { (None, {
'fields': ('name', 'facility_category', 'facility_location', 'fields': ('name', 'facility_category', 'facility_location',
'main_schedule', 'special_schedules', ), 'main_schedule', 'special_schedules', 'owners'),
}),
('Advanced', {
'fields': ('owners', ),
'classes': ('collapse', ),
}), }),
) )
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): class ScheduleAdmin(admin.ModelAdmin):
"""
"""
list_display = ['name', 'modified'] list_display = ['name', 'modified']
inlines = [OpenTimeInline, ] inlines = [OpenTimeInline, ]
fieldsets = ( fieldsets = (
(None, { (None, {
# (name, (start, end)) 'fields': ('name',
'fields': ('name', ('valid_start', 'valid_end')) # Pair valid_start and valid_end together on the same
# line
('valid_start', 'valid_end'))
}), }),
) )
class CategoryAdmin(admin.ModelAdmin): # Register the administration panels
pass # https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects
class LocationAdmin(admin.ModelAdmin):
pass
admin.site.register(Facility, FacilityAdmin) admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin) admin.site.register(Schedule, ScheduleAdmin)
admin.site.register(Category, CategoryAdmin) # Use the default ModelAdmin interface for these
admin.site.register(Location, LocationAdmin) admin.site.register(Category)
admin.site.register(Location)
...@@ -19,7 +19,7 @@ class Category(TimeStampedModel): ...@@ -19,7 +19,7 @@ class Category(TimeStampedModel):
class Meta: class Meta:
verbose_name = "category" verbose_name = "category"
verbose_name_plural = "categories" verbose_name_plural = "categories"
# Sort by name in admin view # Sort by name in admin view.
ordering = ['name'] ordering = ['name']
def __str__(self): def __str__(self):
...@@ -27,16 +27,27 @@ class Category(TimeStampedModel): ...@@ -27,16 +27,27 @@ class Category(TimeStampedModel):
class Location(TimeStampedModel): class Location(TimeStampedModel):
""" """
Represents a specific location (unique lat, lon) that a Facility can be Represents a specific location that a Facility can be found.
found in real life.
""" """
# The building that the facility is located in (on campus) # The building that the facility is located in (on campus).
building = models.CharField(max_length=100, null=True, blank=True) building = models.CharField(max_length=100)
# The physical address of the facility # The physical address of the facility.
address = models.CharField(max_length=100, null=True, blank=True) address = models.CharField(max_length=100)
# Boolean for whether or not the location is "on campus" or not # Boolean for whether or not the location is "on campus" or not.
on_campus = models.BooleanField(default=True) 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): class Facility(TimeStampedModel):
""" """
Represents a specific facility location. Represents a specific facility location.
......
"""
Rest Framework Serializers
"""
# Future Imports # Future Imports
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
...@@ -8,26 +11,25 @@ from .models import Category, Facility, Schedule, OpenTime, Location ...@@ -8,26 +11,25 @@ from .models import Category, Facility, Schedule, OpenTime, Location
# Other Imports # Other Imports
from rest_framework import serializers from rest_framework import serializers
class CategorySerializer(serializers.ModelSerializer): class OpenTimeSerializer(serializers.ModelSerializer):
""" """
""" """
class Meta: class Meta:
model = Category model = OpenTime
fields = '__all__' fields = '__all__'
class LocationSerializer(serializers.ModelSerializer): class CategorySerializer(serializers.ModelSerializer):
""" """
""" """
class Meta: class Meta:
model = Location model = Category
fields = '__all__' fields = '__all__'
class LocationSerializer(serializers.ModelSerializer):
class OpenTimeSerializer(serializers.ModelSerializer):
""" """
""" """
class Meta: class Meta:
model = OpenTime model = Location
fields = '__all__' fields = '__all__'
class ScheduleSerializer(serializers.ModelSerializer): class ScheduleSerializer(serializers.ModelSerializer):
...@@ -50,5 +52,5 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer): ...@@ -50,5 +52,5 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Facility model = Facility
fields = ('id', 'facility_category', 'facility_location', 'main_schedule', fields = ('id', 'facility_category', 'facility_location',
'special_schedules', 'modified', 'name') 'main_schedule', 'special_schedules', 'modified', 'name')
...@@ -7,7 +7,8 @@ from django.conf.urls import include, url ...@@ -7,7 +7,8 @@ from django.conf.urls import include, url
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
# App Imports # App Imports
from .views import CategoryViewSet, FacilityViewSet, ScheduleViewSet, LocationViewSet from .views import (CategoryViewSet, FacilityViewSet, ScheduleViewSet,
LocationViewSet)
# Other Imports # Other Imports
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
...@@ -19,7 +20,7 @@ ROUTER = DefaultRouter() ...@@ -19,7 +20,7 @@ ROUTER = DefaultRouter()
ROUTER.register(r'categories', CategoryViewSet) ROUTER.register(r'categories', CategoryViewSet)
ROUTER.register(r'facilities', FacilityViewSet) ROUTER.register(r'facilities', FacilityViewSet)
ROUTER.register(r'schedules', ScheduleViewSet) ROUTER.register(r'schedules', ScheduleViewSet)
ROUTER.register(r'location', LocationViewSet) ROUTER.register(r'locations', LocationViewSet)
urlpatterns = [ urlpatterns = [
# / - Default route # / - Default route
......
"""
Rest Framework Class Views
"""
# Future Imports # Future Imports
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
...@@ -5,12 +8,12 @@ from __future__ import (absolute_import, division, print_function, ...@@ -5,12 +8,12 @@ from __future__ import (absolute_import, division, print_function,
# App Imports # App Imports
from .models import Facility, OpenTime, Category, Schedule, Location from .models import Facility, OpenTime, Category, Schedule, Location
from .serializers import (CategorySerializer, FacilitySerializer, from .serializers import (CategorySerializer, FacilitySerializer,
ScheduleSerializer, OpenTimeSerializer, LocationSerializer) ScheduleSerializer, OpenTimeSerializer,
LocationSerializer)
# Other Imports # Other Imports
from rest_framework import viewsets from rest_framework import viewsets
# Rest Framework Class Views
class CategoryViewSet(viewsets.ReadOnlyModelViewSet): 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