1

Hi im very novice at python django.

This is my django views.py codes

def post_list(request):
request.session['lat'] = request.POST['user_lat']
request.session['lon'] = request.POST['user_lon']
userpoint = GEOSGeometry('POINT('lat' 'lon')', srid=4326)
list_total = list_1
i=1
while i:
    list_i = Post.objects.filter(point_distance__lte = userpoint, D(km=i)
    list_total = 'list_total' + ',' + 'list_i')
    result_list = list(chain(list_total))
    if len(result_list) >= 50 :
        break

template = loader.get_template('blog/index.html')
context = {
    'post_list': post_list,
}

return HttpResponse(template.render(context, request))

First of all, I want make list to using request.session[]=request.POST[] to make coordinates and this coordinates will be used on my pointfield at 'model.py' is it possible? or is it has any problems?

And Second, in terminal(ubuntu16.04), i used python3 manage.py makemigrations command, it gave me messages as follows, from codes like this,

request.session['lat'] = request.POST['user_lat']
request.session['lon'] = request.POST['user_lon']
userpoint = GEOSGeometry('POINT('lat' 'lon')', srid=4326)

error occured like this->

userpoint = GEOSGeometry('POINT('lat' 'lon')', srid=4326)
                                  ^
                               SyntaxError: invalid syntax

from code like this ,

list_i = Post.objects.filter(point_distance__lte = userpoint, D(km='i'))
                                                                                                                ^

SyntaxError: positional argument follows keyword argument

this SyntaxError occoured.

Last, from this code,

while i:
    list_i = Post.objects.filter(point_distance__lte = userpoint, D(km=i))
    list_total = 'list_total' + ',' + 'list_i')
    result_list = list(chain(list_total))
    if len(result_list) >= 50 :
        break

-> This SyntaxError occoured.

list_total = list_total + ',' + 'list_i'
         ^

SyntaxError: invalid syntax

How can i solve this problems?

while i:
    list_i = Post.objects.filter(point_distance__lte = userpoint, D(km=i))
    list_total = 'list_total' + ',' + 'list_i')
    result_list = list(chain(list_total))
    if len(result_list) >= 50 :
        break

ps. I want make my own result_list using list(chain()) function, but i wonder it is valid.

itertools - python doc : https://docs.python.org/3.3/library/itertools.html i was according to GEOdjango codes : https://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-lookups

Im using python3 (maybe 3.5) , django 1.9

thanks for reading my questions.

2 Answers 2

2

You can not instantiate a GEOSGeometry object with that mis-formed string. Use

userpoint = GEOSGeometry('POINT('+ latvariable + ' ' + lonvariable +')', srid=4326)

Sign up to request clarification or add additional context in comments.

Comments

1

You've missed the closing backet at line:

list_i = Post.objects.filter(point_distance__lte = userpoint, D(km=i)

2 Comments

Thank you. But even after i added backet, 'SyntaxError: positional argument follows keyword argument' has been made at 'D(km=i) '. how can i solve it?
@touchingtwist list_i = Post.objects.filter(D(km=i), point_distance__lte = userpoint)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.