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):
# The name of the Facility
facility_name = models.CharField(max_length=100)
# 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
facility_category = models.ForeignKey('Category',
......
......@@ -88,12 +88,33 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
GET /api/facilities/?closed_now
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
serializer_class = FacilitySerializer
filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter, )
search_fields = ('facility_name',)
ordering_fields = ('facility_name',)
filter_fields = ('facility_name', 'facility_product_tags__name')
filter_backends = (filters.SearchFilter, DjangoFilterBackend,
filters.OrderingFilter, )
search_fields = FILTER_FIELDS
ordering_fields = FILTER_FIELDS
filter_fields = FILTER_FIELDS
def get_queryset(self):
"""
......@@ -162,4 +183,4 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
Handle incoming GET requests and enumerate objects that get returned by
the API.
"""
return OpenTime.objects.all()
\ No newline at end of file
return OpenTime.objects.all()
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