Django model property geo distance -


I am trying to apply the proximity search based on latitude and longitude using Django and Postgresql. I have an abstract version of the model. Class items (models.Model): "" "Dossstrings for items" "uuid = UUIDField (primary_key = true, auto = true) name = model.carfild (_ (" name " ) = = Model = _Keyfield (_ ('location'), max_length = 40, and the address = Blank = true, null = true) @property def geo_distance (self, location = none): if the location is nothing: cursor = connection.cursor () cursor.xicute ("SELECT geo_distance CAST ('% s')) POINT , CAST ('% s' AS POINT) "% self.location, location) return round (float (curse) .itchin) * 1.621371192237), 2)

I want to be able to do something like this, such as view.py:

  items = Item.Abject.Filter (name__istartwith = "anything") Results = [] Items in items for: results.append ({'name': item.name, 'distance': item.geo_distance ("(11.23123, -12.123213 ) ")}))  

I welcome any suggestion that this is not the best way.

If you search based on latitude and longitude then I would recommend you. You can use to calculate the distance between point two or the surrounding area from the point of the point. It is better to write the calculation of distance by using it. For my information, the Django does not support the process of making the process; I did some benchmark in terms of distance calculation, instead of computing the end of the digengo, the processes got faster. Good Luck.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -