'How to fetche the near point (X,Y) object stored in db by filter

I want to fetch the near data.

for example in this case

id x        y
1  243.242  5124.3242
2  143.242  4724.3242
3  240.242  374.3242
4  243.242  1424.3242

I want to get the point near 240,240

in this case 3 is most close to the point.

I can do this after fetch the item row by row.

However it takes so much time.

I want to do this like filter or Q for django model.

How can I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source