[Answer]-Django: Filtering Queryset From Two Model Fields

1👍

The most straightforward way to do this is as @karthikr has said in the comments to your question, just AND the two:

z = Thing.objects.filter(lat=pnt.get_x(), lng = pnt.get_y())

Alternatively, I don’t know how much leeway you have in the database, but you could also store the points separately from your Thing object, and then just link the Thing object to a Point?

psuedocode:

class Thing(models.Model):
   point = models.ForeignKey('Point')

class Point(models.Model):
   lat = models.FloatField()
   lon = models.FloatField()


z = Thing.objects.filter(point = Point.objects.get(lat, long))

Otherwise, I don’t think there’s a way to do what you’re asking.

Leave a comment