예제 #1
0
    def get_queryset(self):
        queryset = self.model.objects.filter(is_active=True)
        if not self.form.is_valid():
            return queryset

        data = self.form.cleaned_data

        group = data.get('group', None)
        if group:
            queryset = queryset.filter(group=group)

        latlng = self.form.point
        if latlng:
            # Convert to geographic coords
            queryset = queryset.transform(get_geographic_srid())

            # Constrain by distance if set up
            max_distance = self.get_max_distance()
            if max_distance:
                queryset = queryset.filter(
                    location__distance_lte=(latlng, max_distance))

            # Add distance query
            queryset = queryset.distance(latlng)

            # Convert back to geodetic coords
            queryset = queryset.transform(get_geodetic_srid())

            # Order by distance
            queryset = queryset.order_by('distance')

        return queryset
예제 #2
0
    def get_queryset(self):
        queryset = self.model.objects.filter(is_active=True)

        group = self.request.POST.get('group', None)
        if group:
            queryset = queryset.filter(group=group)

        location = self.request.POST.get('location', None)
        if location:
            point = GEOSGeometry(location)
            queryset = queryset.transform(
                get_geographic_srid()
            ).distance(
                point
            ).transform(
                get_geodetic_srid()
            ).order_by('distance')
        return queryset
예제 #3
0
    def get_queryset(self):
        queryset = self.model.objects.filter(is_active=True)
        if not self.form.is_valid():
            return queryset

        data = self.form.cleaned_data

        group = data.get('group', None)
        if group:
            queryset = queryset.filter(group=group)

        latlng = self.form.point
        if latlng:
            queryset = queryset.transform(
                get_geographic_srid()).distance(latlng).transform(
                    get_geodetic_srid()).order_by('distance')

        return queryset
예제 #4
0
    def get_queryset(self):
        queryset = self.model.objects.filter(is_active=True)
        if not self.form.is_valid():
            return queryset

        data = self.form.cleaned_data

        group = data.get('group', None)
        if group:
            queryset = queryset.filter(group=group)

        latlng = self.form.point
        if latlng:
            queryset = queryset.transform(
                get_geographic_srid()
            ).distance(
                latlng
            ).transform(
                get_geodetic_srid()
            ).order_by('distance')

        return queryset