from rest_framework.mixins import ListModelMixin
from rest_framework.viewsets import GenericViewSet
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from pollingstations.models import PollingStation


class PollingStationSerializer(GeoFeatureModelSerializer):

    class Meta:
        model = PollingStation
        geo_field = 'location'
        fields = ('council', 'postcode', 'address', 'location')


class PollingStationViewSet(GenericViewSet, ListModelMixin):
    queryset = PollingStation.objects.all()
    serializer_class = PollingStationSerializer

from rest_framework.decorators import list_route
from rest_framework.mixins import ListModelMixin
from rest_framework.viewsets import GenericViewSet
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from pollingstations.models import PollingStation


class PollingStationSerializer(GeoFeatureModelSerializer):

    class Meta:
        model = PollingStation
        geo_field = 'location'
        fields = ('council', 'postcode', 'address', 'location')


class PollingStationViewSet(GenericViewSet, ListModelMixin):
    queryset = PollingStation.objects.all()
    serializer_class = PollingStationSerializer

    @list_route(url_path='geo')
    def geo(self, request, format=None):
        return self.list(request, format=None)

add optional /geo suffix to /pollingstations