I know i could have used python’s own functional tool-set, but I wish there’s a way to this in Django.
I have this model:
class AssetGeoFenceEvent(models.Model):
#...
#assets, for which this event is assigned
asset = models.ForeignKey(Asset)
#...
and the referenced Asset model is like:
class Asset(models.Model):
#...
client = models.ForeignKey(Client)
#....
I thought I could do:
#get all the registered events for this client
events = AssetGeoFenceEvent.objects.filter(asset.client == client)
but that fails with error :
keyword can’t be an expression
Tried this but it fails:
#get all the registered events for this client
events = AssetGeoFenceEvent.objects.filter(lambda a: a.client == client)
Which gives me an error
‘function’ object is not iterable
So how can I pull this off using Django?
You’re doing it wrong.