-2

I'm trying to get a string as a variable to represent my column in DB.

l_id =1
level=7
test = "level"+level
device_level_mapping = DeviceLevelMapping.objects.filter(test = l_id)

It says keyword cant be an expression.

I need to do something like this. In PHP we do like this.

$a = "test"+"1";
$$a = 10;
echo $test1; // now test1 has become a variable.

How do I make this happen in python?

PythonEnthusiast
  • 15,691
  • 41
  • 122
  • 238

1 Answers1

1
test = "level"+level
d = {test: l_id}
device_level_mapping = DeviceLevelMapping.objects.filter(**d)
Naster
  • 344
  • 1
  • 7