Hi everyone! I have a "Services" model and I would like to get a
QuerySet with all the services filtered based on the distance between
the logged user and the service.

I have latitude and longitude about the user logged in and I filter
the services based on the computed distance.

At the moment I build the QuerySet Service.objects.all() and after
that I exclude the services that I don't need, but I think there is a
better way to do that.

I was thinking to use a Manager. Quoting the docs:

"Adding extra Manager methods is the preferred way to add
“table-level” functionality to your models. (For “row-level”
functionality – i.e., functions that act on a single instance of a
model object – use Model methods, not custom Manager methods.)"

As a "eternal newbie" I ask you

1) The distance must be computed based on two parameters "long" and
"lat". Is that possible to define a manager only for this purpose? Is
it a good practice?

2) The computed value is not just useful for the QuerySet, but I need
also that on client side so I serialize it and I send it using JSON.
Is possible to make sure that the manager attach the field "distance"
to the objects in the QuerySet?

Thank you!

-- 
Karim N. Gorjux

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACeuRGUPt5f52oABVifeu2%3DPeYHLAAekrGwbVocvdDGQeyQJgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to