Commit 5d1bf519 authored by Nicolas Joyard's avatar Nicolas Joyard

Use RQLFilterBackend; show mandates in rep list

parent 4639bd42
......@@ -7,6 +7,8 @@ from rest_framework import (
viewsets,
)
from rql_filter.backend import RQLFilterBackend
from representatives.serializers import (
ChamberSerializer,
ConstituencySerializer,
......@@ -51,7 +53,8 @@ class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet):
filter_backends = (
filters.DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter
filters.OrderingFilter,
RQLFilterBackend
)
filter_fields = {
'active': ['exact'],
......@@ -105,7 +108,8 @@ class MandateViewSet(viewsets.ReadOnlyModelViewSet):
filter_backends = (
filters.DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter
filters.OrderingFilter,
RQLFilterBackend
)
filter_fields = {
'id': ['exact'],
......@@ -120,20 +124,36 @@ class ConstituencyViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Constituency.objects.all()
serializer_class = ConstituencySerializer
filter_backends = (
RQLFilterBackend,
)
class GroupViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Group.objects.all()
serializer_class = GroupSerializer
filter_backends = (
RQLFilterBackend,
)
class ChamberViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Chamber.objects.all()
serializer_class = ChamberSerializer
filter_backends = (
RQLFilterBackend,
)
class CountryViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Country.objects.all()
serializer_class = CountrySerializer
filter_backends = (
RQLFilterBackend,
)
......@@ -156,6 +156,8 @@ class MandateDetailSerializer(MandateSerializer):
class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
contacts = ContactField()
mandates = MandateDetailSerializer(many=True)
class Meta:
model = models.Representative
fields = (
......@@ -172,6 +174,7 @@ class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
'active',
'cv',
'contacts',
'mandates'
)
extra_kwargs = {
'url': {'view_name': 'api-representative-detail'},
......@@ -179,10 +182,4 @@ class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
class RepresentativeDetailSerializer(RepresentativeSerializer):
mandates = MandateDetailSerializer(many=True)
class Meta(RepresentativeSerializer.Meta):
fields = RepresentativeSerializer.Meta.fields + (
'mandates',
)
pass
......@@ -19,6 +19,7 @@ setup(
'celery': 'celery',
'api': [
'django-filter>=0.13,<0.14',
'django-rql-filter>=0.1.3,<0.2',
'djangorestframework>=3,<4',
],
'testing': [
......
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