Karim
unread,Dec 9, 2014, 7:09:05 PM12/9/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django Users
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