I’m trying to execute a Django query:
#att.name is a string
kwargs = {att.name : F('node__product__' + att.name) }
temps = Temp.objects.exclude(**kwargs)
I’m wondering if this is correct. All the examples I’ve seen so far use strings in the values, but what if the value is a function, should I make the value a string, like this?
kwargs = {att.name : 'F('node__product__' + att.name)' }
Does the function in the value get executed eagerly in the argument list or does it wait until it’s needed?
In python, expressions are always evaluated eagerly. There is no lazy evaluation in python. Some libraries get around the absence of this useful feature by allowing values that should be of some specific type to instead be a string, which it later
evals. You can declare some parts of a django model this way (so that you can declare mutually referential foreign key relationships), but django’s query interface does not. You wouldn’t normally be able to use this kind of technique when a string is “expected”, because you’d have no way to distinguish string values from strings that should beevaled.