Vaibhav Mishra
Vaibhav Mishra

Reputation: 103

Running Django Model Query for more than one value for same Field

I would like to know how can we run queries from Django Model if we want to retrieve more than one value for same field

For Example This is my Model

class Ball(models.Model):
    Ballname  =  models.CharField(max_length=8,primary_key=True)
    Ballcolor =  models.CharField(max_length=10)

I am trying to get All Balls of Red and White Color

dataset = data.filter(Ballcolor="red", Ballcolor ="white")

But I get an error saying same field cant be used more than once. How do I get about getting this data ?

Upvotes: 0

Views: 27

Answers (1)

Sergey Pugach
Sergey Pugach

Reputation: 5669

You can do it with in

dataset = data.filter(Ballcolor__in=['red','white'])

Upvotes: 2

Related Questions