These are chat archives for django/django

1st
Jul 2017
djangoReactGuy
@SanskarSans
Jul 01 2017 05:53

The current location of user might change in a minutes. For example if a user is in location A,
he will get the list of property around 15km from his current location but if he is moving now and
has crossed the 5km from the previous location now show the property around 15km from the new
location. How can i handle such situation?

Right now this is my code to find nearby property around 15km.

@api_view(['GET', ])
def nearby_property_finder(request, current_latitude, current_longitude):
    user_location = Point(float(current_longitude), float(current_latitude))
    distance_from_point = {'km': 15}
    properties = Property.gis.filter(location__distance_lte=(user_location,D(**distance_from_point)))
    properties = properties.distance(user_location).order_by('distance')
    if properties.exists():
        paginator = ResultInPagination()
        paginated_properties = paginator.paginate_queryset(properties, request)
        serializer=PropertySerializer(paginated_properties, many=True)
        return paginator.get_paginated_response(serializer.data)
    else:
        return Response({}, status=status.HTTP_200_OK)
djangoReactGuy
@SanskarSans
Jul 01 2017 13:48
How do i associate multiple images to Property?
class PropertyGallery(APIView):
    serializer_class = GallerySerializer
    parser_classes = (FormParser, MultiPartParser, )
    def put(self, request, property_id=None, format=None):
        serializer = self.serializer_class(data=request.data, partial=True)
        if not serializer.is_valid():
            return Response(serializer.errors, status= status.HTTP_400_BAD_REQUEST)
        else:
            serializer.save()
            return Response(serializer.data, status= status.HTTP_200_OK)

class GallerySerializer(serializers.ModelSerializer):
    class Meta:
        model = Gallery
        fields=('id', 'caption', 'image', )

class PropertySerializer(serializers.ModelSerializer, EagerLoadingMixin):
    _SELECT_RELATED_FIELDS = ['owner', ]
    _PREFETCH_RELATED_FIELDS = ['property_type',]
    gallery = GallerySerializer(many=True)

class Property(models.Model):
    """Model for all properties."""
    owner = models.ForeignKey(settings.AUTH_USER_MODEL)
    address = models.CharField(_('Address'), max_length=140)

class Gallery(models.Model):
    property_instance = models.ForeignKey(Property, related_name="gallery")
    caption = models.CharField(null=True, blank=True, max_length=80)
    image = models.ImageField(upload_to="properties/rooms/")
Anish Shrestha
@annshress
Jul 01 2017 14:50
@SanskarSans what are you using to calculare distance.
    properties = Property.gis.filter(location__distance_lte=(user_location,D(**distance_from_point)))
    properties = properties.distance(user_location).order_by('distance')
Can you help me with this?
djangoReactGuy
@SanskarSans
Jul 01 2017 15:22
@annshress I am using django.contrib.gis package for calculating the distance
Anish Shrestha
@annshress
Jul 01 2017 15:24
Hmm, I did not know about this earlier.
djangoReactGuy
@SanskarSans
Jul 01 2017 15:24
I am querying the property using gis manager. Using the location field i filter the query to return properties not further away than 15 km, and filtered by distance to given address (geocoded to coordinates)
Anish Shrestha
@annshress
Jul 01 2017 15:27
location__distance_lte this is calculated by gis package?
location must be your field
and distance is calculated?
djangoReactGuy
@SanskarSans
Jul 01 2017 15:29
location is the PointField which is not using django models field but a gis models
as django model has not PointField
its a combination of postgres, geodjango and gis
Anish Shrestha
@annshress
Jul 01 2017 15:31
Hmm. I should have known this earlier. I have done this manually, annotating distance and stuff
So, dont you think, like you can throttle your request and send lat/long to get new set of properties
???
I think, throttling is your way to go?
I think this is what you want./
djangoReactGuy
@SanskarSans
Jul 01 2017 15:33
I am now thinking of using websocket to send the current location of user
Anish Shrestha
@annshress
Jul 01 2017 15:33
websocket can be resource consuming
djangoReactGuy
@SanskarSans
Jul 01 2017 15:33
I am intending to use react native which has geolocation api
Anish Shrestha
@annshress
Jul 01 2017 15:33
Dont you think?
djangoReactGuy
@SanskarSans
Jul 01 2017 15:35
That is why i want to take others idea. Thanks @annshress for your suggestion. I have never considered the throttling feature . I will sure look into this
I had celery in my mind but it might be overkill
Kaushal Kumar
@kaushal087
Jul 01 2017 17:54
What are some good quiz app for django 1.10? I have seen https://github.com/tomwalker/django_quiz . It's really good but it's for django 1.8
John
@flyboy1565
Jul 01 2017 19:25
Why not rewrite it for your self in Django 1.10