Filter on properties

34 views
Skip to first unread message

Joakim Jacobsen

unread,
Apr 7, 2016, 6:16:33 AM4/7/16
to Django REST Framework GIS
Is it possible to filter on the other model attributes(properties in geojson) than geometry when using a GeoFeatureModelSerializer?

Federico Capoano

unread,
Apr 11, 2016, 8:59:43 AM4/11/16
to Django REST Framework GIS
Hi Joakim,

I haven't understood your question.

Could you provide some context and show some code samples for your situation please?

Federico

Joakim Jacobsen

unread,
Apr 15, 2016, 5:49:42 AM4/15/16
to Django REST Framework GIS
Thanks for the reply and the great application!

My issues was regarding filtering in views on models using the GeoFeatureModelSerializer. I thought I had to access the attributes like this: properties.attr, or something like that.

class WorkOrderFilter(filterset.GeoFilterSet):
products = UUIDFilter(name='products__product_id', lookup_type='exact')
contains_geom = GeometryFilter(name='footprint', lookup_type='contains')
projects = NumberFilter(name='projects__project_uuid', lookup_type='exact')

class Meta:
model = WorkOrder
fields = ['products', 'contains_geom']


class WorkOrderViewSet(viewsets.ModelViewSet):
queryset = WorkOrder.objects.all()
serializer_class = WorkOrderSerializer
bbox_filter_field = 'footprint'
filter_backends = (filters.DjangoFilterBackend, InBBoxFilter)
bbox_filter_include_overlapping = True
filter_class = WorkOrderFilter
filter_fields = ['products', 'contains_geom']

So here products is a list of UUID's under properties, following the GeoJSON spec. I got this to work.

Additional question:
Is it possible to use the Browsable API search Form with the GeoFeatureModelSerializer ?

Joakim

Nemesis

unread,
Apr 15, 2016, 6:13:34 AM4/15/16
to django-rest-...@googlegroups.com
On 04/15/2016 11:49 AM, Joakim Jacobsen wrote:
> Thanks for the reply and the great application!
>
> My issues was regarding filtering in views on models using
> the GeoFeatureModelSerializer. I thought I had to access the attributes
> like this: properties.attr, or something like that.
>

[CUT]

>
> So here products is a list of UUID's under properties, following the
> GeoJSON spec. I got this to work.

Great news!

> Additional question:
> Is it possible to use the Browsable API search Form with
> the GeoFeatureModelSerializer ?

I have never done this yet and I don't know if anyone has done it, BUT
you could try to ask on stackoverflow.com, (be sure to include the
django-rest-framework tag) this way you should be able to get more
visibility to your question.

If we find a nice solution we could even add a few lines about this in
the documentation.

Federico

Federico Capoano

unread,
Apr 18, 2016, 5:45:02 AM4/18/16
to Django REST Framework GIS
The django-rest-framework-gis tag has been approved on stackoverflow.com.
Please use this tag if you post your question there.

I will be encouraging more users to do this because here there's basically only me answering.
If it's adopted I'll update the docs.

Federico
Reply all
Reply to author
Forward
0 new messages