Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

Commit

Permalink
add filterset for buys api
Browse files Browse the repository at this point in the history
  • Loading branch information
stvnrlly committed Dec 6, 2016
1 parent 332d213 commit 831e548
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 20 additions & 0 deletions projects/filters.py
@@ -0,0 +1,20 @@
import django_filters
from projects.models import IAA, Project, Buy


class BuyFilter(django_filters.rest_framework.FilterSet):
min_dollars = django_filters.NumberFilter(
name="dollars",
lookup_expr='gte',
)
max_dollars = django_filters.NumberFilter(
name="dollars",
lookup_expr='lte',
)

class Meta:
model = Buy
# Allowing filtering by project leaks non-public project names in the
# browseable API, so it cannot be provided here until the browseable
# API is turned off
fields = ['id', 'name', 'min_dollars', 'max_dollars']
5 changes: 2 additions & 3 deletions projects/views.py
Expand Up @@ -16,6 +16,7 @@
from projects.models import IAA, Project, Buy
from projects.serializers import IAASerializer, ProjectSerializer, BuySerializer
from projects.forms import QASPForm, AcquisitionPlanForm, MarketResearchForm
from projects.filters import BuyFilter
from nda.forms import NDAForm


Expand Down Expand Up @@ -284,9 +285,7 @@ class BuyList(mixins.ListModelMixin,
List all buys
"""
serializer_class = BuySerializer
# TODO: fancier filterset:
# http://www.django-rest-framework.org/api-guide/filtering/#specifying-a-filterset
filter_fields = ('name',)
filter_class = BuyFilter

def get_queryset(self):
if self.request.user.has_perm('projects.view_project'):
Expand Down

0 comments on commit 831e548

Please sign in to comment.