eachone
eachone

Reputation: 577

Excluding some rows in Django queryset

When I want to exclude some data row, I used to use:

entry.object.filter(name__startwith='Tom').exclude(name='foo')

I want to give exclude conditions like below. Is it possible?

entry.object.filter(name__startwith='Tom').exclude(name=['bar','foo'])

Could you give me some solutions?

Upvotes: 0

Views: 1223

Answers (1)

Leistungsabfall
Leistungsabfall

Reputation: 6488

To check if name is included in a list, use __in:

entry.object.filter(name__startwith='Tom').exclude(name__in=['bar','foo'])

Link to the docs.

Upvotes: 6

Related Questions