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

Finish first pass on Facility filtering

- define FILTER_FIELDS that lists all model fields that are available to
filter on
parent 74779e8b
...@@ -83,7 +83,7 @@ class Facility(TimeStampedModel): ...@@ -83,7 +83,7 @@ class Facility(TimeStampedModel):
# The name of the Facility # The name of the Facility
facility_name = models.CharField(max_length=100) facility_name = models.CharField(max_length=100)
# Instead of id # Instead of id
slug = AutoSlugField(populate_from='name', unique=True) slug = AutoSlugField(populate_from='facility_name', unique=True)
# The category that this facility can be grouped with # The category that this facility can be grouped with
facility_category = models.ForeignKey('Category', facility_category = models.ForeignKey('Category',
......
...@@ -88,12 +88,33 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -88,12 +88,33 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
GET /api/facilities/?closed_now GET /api/facilities/?closed_now
Query parameter that only returns closed Facility objects. Query parameter that only returns closed Facility objects.
""" """
FILTER_FIELDS = (
# Facility fields
'facility_name',
'tapingo_url',
'facility_product_tags__name',
# Category fields
'facility_category__name',
# Location fields
'facility_location__building',
'facility_location__address',
'facility_location__on_campus',
# Schedule fields
'main_schedule__name',
'main_schedule__valid_start',
'main_schedule__valid_end',
'special_schedules__name',
'special_schedules__valid_start',
'special_schedules__valid_end',
)
# Associate a serializer with the ViewSet # Associate a serializer with the ViewSet
serializer_class = FacilitySerializer serializer_class = FacilitySerializer
filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter, ) filter_backends = (filters.SearchFilter, DjangoFilterBackend,
search_fields = ('facility_name',) filters.OrderingFilter, )
ordering_fields = ('facility_name',) search_fields = FILTER_FIELDS
filter_fields = ('facility_name', 'facility_product_tags__name') ordering_fields = FILTER_FIELDS
filter_fields = FILTER_FIELDS
def get_queryset(self): def get_queryset(self):
""" """
...@@ -162,4 +183,4 @@ class OpenTimeViewSet(viewsets.ModelViewSet): ...@@ -162,4 +183,4 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
Handle incoming GET requests and enumerate objects that get returned by Handle incoming GET requests and enumerate objects that get returned by
the API. the API.
""" """
return OpenTime.objects.all() return OpenTime.objects.all()
\ No newline at end of file
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