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 8327115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:59:45+00:00 2026-06-09T00:59:45+00:00

Possible Duplicate: Django Tastypie Advanced Filtering: How to do complex lookups with Q objects

  • 0

Possible Duplicate:
Django Tastypie Advanced Filtering: How to do complex lookups with Q objects

I have a tastypie modelRseource that looks like this:

class TaggedResource(ModelResource):
    tags = ListField()
    user = fields.ForeignKey(UserProfileResource, 'user')

    class Meta:
        queryset = Media.objects.all().order_by('-timestamp')
        authorization = MediaAuthorization()
        detail_allowed_methods = ['get', 'post', 'put', 'delete','patch']

    filtering = {
        #'user': ALL_WITH_RELATIONS,
        #exact is date, lt is less than lte less than equal to, etc
        'timestamp': ['exact', 'range', 'lt', 'lte', 'gte', 'gt'],
        'social_source': ALL,
        'media_type': ALL,
        'comment': ['exact', 'startswith', 'endswith', 'contains'],
        'media_text': ['exact', 'startswith', 'endswith', 'contains'],
    }

I need to have an OR operator between filters and would love to combine the query into one parameter. For example, I want to return objects that contain the word “test” filtering from the comment field OR media_text field.

This would be ideal: http:mysite.com/api/v1/tagged?q=test

where ‘q’ performs an OR filter for both fields.

Is this doable?

UPDATE: Here is what I am working on with advanced filters but am not really sure how to get an OR statement:

def build_filters(self, filters=None):
    if filters is None:
        filters = {}

    orm_filters = super(TaggedResource, self).build_filters(filters)

    if 'q' in filters:
        orm_filters['comment__contains'] = filters['q']
        orm_filters['media_text__contains'] = filters['q'] 
    return orm_filters  
  • 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-06-09T00:59:48+00:00Added an answer on June 9, 2026 at 12:59 am

    You’re doing the right thing by overriding build_filters, you can use django’s Q class for AND/OR queries, I have answered a similar question here

    Tastypie filtering with multiple values

    and here’s another interesting one:

    Tastypie Negation Filter

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

Sidebar

Related Questions

Possible Duplicate: Are there any all in one packages like XAMPP for Django? Is
Possible Duplicate: Django view - load template from calling app's dir first I have
Possible Duplicate: Array to named variables How can I convert an array like this
Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: Django models: default value for column I have created a model field
Possible Duplicate: How do you select between two dates with Django I have django
Possible Duplicate: Django switching, for a block of code, switch the language so translations
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Django dynamic model fields Good Morning guys! Scenario is the following. For

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.