Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:00:58+00:00 2026-05-31T13:00:58+00:00

Is there a negation filter available by default. The idea is that you can

  • 0

Is there a negation filter available by default. The idea is that you can do the following in the django ORM:

model.objects.filter(field!=value)

How can I do that in tastypie if that is even possible. I tried:

someapi.com/resource/pk/?field__not=value
someapi.com/resource/pk/?field__!=value
someapi.com/resource/pk/?field!=value

And all of them given me errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:00:59+00:00Added an answer on May 31, 2026 at 1:00 pm

    Unfortunately there’s not.

    The problem is that Tastypie’s ModelResource class uses the filter() method of the QuerySet only, i.e. it does not use exclude() which should be used for negative filters. There is no filter() field lookup that would mean negation though. The valid lookups are (after this SO post):

    exact
    iexact
    contains
    icontains
    in
    gt
    gte
    lt
    lte
    startswith
    istartswith
    endswith
    iendswith
    range
    year
    month
    day
    week_day
    isnull
    search
    regex
    iregex
    

    However it shouldn’t be so hard to implement the support for something like “__not_eq”. All you need to do is to modify the apply_filters() method and separate filters with “__not_eq” from the rest. Then you should pass the first group to exclude() and the rest to filter().

    Something like:

    def apply_filters(self, request, applicable_filters):
        """
        An ORM-specific implementation of ``apply_filters``.
    
        The default simply applies the ``applicable_filters`` as ``**kwargs``,
        but should make it possible to do more advanced things.
        """
        positive_filters = {}
        negative_filters = {}
        for lookup in applicable_filters.keys():
            if lookup.endswith( '__not_eq' ):
                negative_filters[ lookup ] = applicable_filters[ lookup ]
            else:
                positive_filters[ lookup ] = applicable_filters[ lookup ]
    
        return self.get_object_list(request).filter(**positive_filters).exclude(**negative_filters)
    

    instead of the default:

    def apply_filters(self, request, applicable_filters):
        """
        An ORM-specific implementation of ``apply_filters``.
    
        The default simply applies the ``applicable_filters`` as ``**kwargs``,
        but should make it possible to do more advanced things.
        """
        return self.get_object_list(request).filter(**applicable_filters)
    

    should allow for the following syntax:

    someapi.com/resource/pk/?field__not_eq=value
    

    I haven’t tested it. It could probably be written in more elegant way too, but should get you going 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a field in my company's Contacts table. In that table, there is
I mean, we all know that there is the negation logical operator ! ,
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are several types of objects in a system, and each has it's own
There are so many questions on regex-negation here on SO. I am not sure
There is a website called Gild.com that has different coding puzzles/challenges for users to
I want to write a regular expression that will match the following string a
There is a statement in the foudations of Qt Development book that goes as
As far as I can see, there are three ways to use Booleans in
I have a Django site, with an Item object that has a boolean property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.