python - Django Querying By a Set Relationship (Reverse) -


i have class called toy, in toys either animals or fruits.

some example database,

|name|type|pk| |jerry|cat|33| |scoobie|dog|52| |leslie|dog|73| |helen|strawbery|86| |mark|banana|16| 

when user selects 'animals', should output jerry, scoobie, leslie, if selects 'fruits' should output helen, mark.

i need below

mydict={'animal':'cat' or 'dog', 'fruits':'strawberry' or 'banana'} toy.objects.filter(type = mydict[input]) 

or

mydict={'animal':['cat' ,'dog'], 'fruits':['strawberry' , 'banana']} toy.objects.filter(type in mydict[input]) 

of course not work, ideas how can proceed?

without knowing how model looks like:

toy.objects.filter(type__in=["dog", "cat"]) 

or

toy.objects.filter(type__in=["strawberry", "banana"]) 

and thirdly (with toy types fruit or animal)

toy.objects.filter(type__in=["dog", "cat", "strawberry", "banana"]) 

since don't store "animal" type according you've described have no need {'animal':[...], 'fruit':[...]}.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -