Eva611
Eva611

Reputation: 6194

Django Query Filter

The following line in my view selects all records that have a delay of 0

t = Times.objects.filter(delay = 0)

How do i write it such that it selects everything but with delay 0?

Upvotes: 0

Views: 104

Answers (4)

jakecar
jakecar

Reputation: 586

Use the exclude() method instead of the filter() method

https://docs.djangoproject.com/en/1.3/topics/db/queries/#retrieving-specific-objects-with-filters

Upvotes: 2

Peter Rowell
Peter Rowell

Reputation: 17713

It's in the docs. You want:

t = Times.objects.filter(delay__ne=0)

Upvotes: 0

Joe Jasinski
Joe Jasinski

Reputation: 10791

Can you try doing?

t = Times.objects.exclude(delay=0)

I think that will work for you.

Hope that helps, Joe

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

With exclude() instead.

Upvotes: 2

Related Questions