In the following code data_var is my object from a Django query, i.e. data_var = Datavar.objects.all(). I have database fields like field1, field2, field3, etc. In the following code I am trying to get the name of the field as a string in var and then say tg.var but I get an error as object has no attribute 'var':
If I say tg.var it should be interpreted as tg.field1 or 2 or 3. How to achieve this?
for tg in data_var:
for col in range(content.no_of_cols):
var = "field" + str(col)
tg.var