Skip to content

Commit

Permalink
Allow more flexible filtering of weight entries
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Nov 7, 2024
1 parent b498275 commit 540f210
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions wger/weight/api/filtersets.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

# 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'],
}
3 changes: 2 additions & 1 deletion wger/weight/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
"""
Expand Down

0 comments on commit 540f210

Please sign in to comment.