From 540f210a15c46afc2ca325b9ebd46ac8f1b7e9c5 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 7 Nov 2024 12:35:27 +0100 Subject: [PATCH] Allow more flexible filtering of weight entries --- wger/weight/api/filtersets.py | 30 ++++++++++++++++++++++++++++++ wger/weight/api/views.py | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 wger/weight/api/filtersets.py diff --git a/wger/weight/api/filtersets.py b/wger/weight/api/filtersets.py new file mode 100644 index 000000000..831b9808f --- /dev/null +++ b/wger/weight/api/filtersets.py @@ -0,0 +1,30 @@ +# This file is part of wger Workout Manager. +# +# wger Workout Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# wger Workout Manager is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Workout Manager. If not, see . + +# Third Party +from django_filters import rest_framework as filters + +# wger +from wger.weight.models import WeightEntry + + +class WeightEntryFilterSet(filters.FilterSet): + class Meta: + model = WeightEntry + fields = { + 'id': ['exact', 'in'], + 'weight': ['exact', 'gt', 'gte', 'lt', 'lte'], + 'date': ['exact', 'gt', 'gte', 'lt', 'lte'], + } diff --git a/wger/weight/api/views.py b/wger/weight/api/views.py index 850ad9efb..70c0f05d9 100644 --- a/wger/weight/api/views.py +++ b/wger/weight/api/views.py @@ -19,6 +19,7 @@ from rest_framework import viewsets # wger +from wger.weight.api.filtersets import WeightEntryFilterSet from wger.weight.api.serializers import WeightEntrySerializer from wger.weight.models import WeightEntry @@ -32,7 +33,7 @@ class WeightEntryViewSet(viewsets.ModelViewSet): is_private = True ordering_fields = '__all__' - filterset_fields = ('date', 'weight') + filterset_class = WeightEntryFilterSet def get_queryset(self): """