mirror of https://github.com/snachodog/mybuddy.git
Add date filters to all relevant models
This commit is contained in:
parent
23f5f76db4
commit
25471b2dc6
|
@ -3,7 +3,7 @@ from django_filters import rest_framework as filters
|
|||
from core import models
|
||||
|
||||
|
||||
class DateFromTimeFieldFilter(filters.FilterSet):
|
||||
class TimeFieldFilter(filters.FilterSet):
|
||||
date = filters.DateFilter(field_name='date', label='Date')
|
||||
date_min = filters.DateFilter(field_name='time__date', label='Min. Date',
|
||||
lookup_expr='gte')
|
||||
|
@ -11,19 +11,56 @@ class DateFromTimeFieldFilter(filters.FilterSet):
|
|||
lookup_expr='lte')
|
||||
|
||||
|
||||
class DiaperChangeFilter(DateFromTimeFieldFilter):
|
||||
class StartEndFieldFilter(filters.FilterSet):
|
||||
end = filters.DateFilter(field_name='end__date', label='End Date')
|
||||
end_min = filters.DateFilter(field_name='end__date', label='Min. End Date',
|
||||
lookup_expr='gte')
|
||||
end_max = filters.DateFilter(field_name='end__date', label='Max. End Date',
|
||||
lookup_expr='lte')
|
||||
start = filters.DateFilter(field_name='start__date', label='Start Date')
|
||||
start_min = filters.DateFilter(field_name='start__date', lookup_expr='gte',
|
||||
label='Min. Start Date',)
|
||||
start_end = filters.DateFilter(field_name='start__date', lookup_expr='lte',
|
||||
label='Max. End Date')
|
||||
|
||||
|
||||
class DiaperChangeFilter(TimeFieldFilter):
|
||||
class Meta:
|
||||
model = models.DiaperChange
|
||||
fields = ['child', 'wet', 'solid', 'color', 'amount']
|
||||
|
||||
|
||||
class NoteFilter(DateFromTimeFieldFilter):
|
||||
class FeedingFilter(StartEndFieldFilter):
|
||||
class Meta:
|
||||
model = models.Feeding
|
||||
fields = ['child', 'type', 'method']
|
||||
|
||||
|
||||
class NoteFilter(TimeFieldFilter):
|
||||
class Meta:
|
||||
model = models.Note
|
||||
fields = ['child']
|
||||
|
||||
|
||||
class TemperatureFilter(DateFromTimeFieldFilter):
|
||||
class SleepFilter(StartEndFieldFilter):
|
||||
class Meta:
|
||||
model = models.Sleep
|
||||
fields = ['child']
|
||||
|
||||
|
||||
class TemperatureFilter(TimeFieldFilter):
|
||||
class Meta:
|
||||
model = models.Temperature
|
||||
fields = ['child']
|
||||
|
||||
|
||||
class TimerFilter(StartEndFieldFilter):
|
||||
class Meta:
|
||||
model = models.Timer
|
||||
fields = ['child', 'active', 'user']
|
||||
|
||||
|
||||
class TummyTimeFilter(StartEndFieldFilter):
|
||||
class Meta:
|
||||
model = models.TummyTime
|
||||
fields = ['child']
|
||||
|
|
12
api/views.py
12
api/views.py
|
@ -11,7 +11,7 @@ class ChildViewSet(viewsets.ModelViewSet):
|
|||
queryset = models.Child.objects.all()
|
||||
serializer_class = serializers.ChildSerializer
|
||||
lookup_field = 'slug'
|
||||
filterset_fields = ('first_name', 'last_name', 'slug')
|
||||
filterset_fields = ('first_name', 'last_name', 'slug', 'birth_date')
|
||||
|
||||
|
||||
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
||||
|
@ -23,7 +23,7 @@ class DiaperChangeViewSet(viewsets.ModelViewSet):
|
|||
class FeedingViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||
queryset = models.Feeding.objects.all()
|
||||
serializer_class = serializers.FeedingSerializer
|
||||
filterset_fields = ('child', 'type', 'method')
|
||||
filterset_class = filters.FeedingFilter
|
||||
|
||||
|
||||
class NoteViewSet(viewsets.ModelViewSet):
|
||||
|
@ -35,7 +35,7 @@ class NoteViewSet(viewsets.ModelViewSet):
|
|||
class SleepViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||
queryset = models.Sleep.objects.all()
|
||||
serializer_class = serializers.SleepSerializer
|
||||
filterset_fields = ('child',)
|
||||
filterset_class = filters.SleepFilter
|
||||
|
||||
|
||||
class TemperatureViewSet(viewsets.ModelViewSet):
|
||||
|
@ -47,16 +47,16 @@ class TemperatureViewSet(viewsets.ModelViewSet):
|
|||
class TimerViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Timer.objects.all()
|
||||
serializer_class = serializers.TimerSerializer
|
||||
filterset_fields = ('child', 'active', 'user')
|
||||
filterset_class = filters.TimerFilter
|
||||
|
||||
|
||||
class TummyTimeViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||
queryset = models.TummyTime.objects.all()
|
||||
serializer_class = serializers.TummyTimeSerializer
|
||||
filterset_fields = ('child',)
|
||||
filterset_class = filters.TummyTimeFilter
|
||||
|
||||
|
||||
class WeightViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Weight.objects.all()
|
||||
serializer_class = serializers.WeightSerializer
|
||||
filterset_fields = ('child',)
|
||||
filterset_fields = ('child', 'date')
|
||||
|
|
Loading…
Reference in New Issue