0

I would like to get specific column from DV table based on input from user.

db :

animal   weight   height

cat        40        20
wolf       100       50

first i need to get what animal user wants

input1='cat'

and then information about the input1 like weight or height

input2='weight'

animalwho=Wildlife.objects.get(animal=input1)

So if i put animalwho.weight it give me 40

But i want to get column based on input2 as input 2 might be height or any other

I tried animalwho.input2 but it does not work.

Is that possible to get column based on input2?

Would apopreciate any help

1 Answers1

0

The easiest solution would be to convert your object to a dict or get dict directly using values.

Many options to convert object to dict see here link

Then you can easily

animalwho_dict=Wildlife.objects.filter(animal=input1).values()[0]

input2_value = animalwho_dict[input2]
neeraj9194
  • 178
  • 9