Skip to content

Instantly share code, notes, and snippets.

@JorgeMichelena
Created September 19, 2022 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorgeMichelena/ad92f9d3763540190cfdf0b6e7218d2e to your computer and use it in GitHub Desktop.
Save JorgeMichelena/ad92f9d3763540190cfdf0b6e7218d2e to your computer and use it in GitHub Desktop.
from django.contrib.gis.db.models.functions import Distance
matching_targets = (
Target.objects
.annotate(distance=Distance("location", my_target.location))
.filter(distance__lte=(F("radius_in_mts") + my_target.radius_in_mts))
.filter(topic=my_target.topic)
.exclude(user_id=my_target.user_id)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment