DRF Filters ?

89 views
Skip to first unread message

Guillaume Moccand

unread,
Mar 19, 2017, 10:23:38 AM3/19/17
to Django REST Framework GIS
 Hi,

Could this configuration apply to DRF when django-rest-framework-gis is used for serializer ?


'DEFAULT_FILTER_BACKENDS': (
    'django_filters.rest_framework.DjangoFilterBackend',
    'rest_framework.filters.SearchFilter'
)
 

my views.py :


class ReferenceGeoViewSet(viewsets.ReadOnlyModelViewSet):
    """
    API endpoint that allows References to be listed as a GeoJson feature collection.
    """
    queryset = Reference.objects.all().order_by('name')
    filter_fields = ('id',)
    search_fields = ('name', 'description')
    pagination_class = None
    serializer_class = ReferenceGeoSerializer
 

and my serializers.py :



from rest_framework_gis.serializers import GeoFeatureModelSerializer

class ReferenceGeoSerializer(GeoFeatureModelSerializer):
    """ A class to serialize locations as GeoJSON compatible data """
    class Meta:
        model = Reference
        geo_field = "geom_point"
        fields = ('id', 'url', 'name', 'description', 'year', 'publication')
 

Trying to add filter as non GIS DRF ModelViewSet i can't get it working.




Reply all
Reply to author
Forward
0 new messages