Combining filters in one request in Tastypie

Possible duplicate:
Advanced Django Tastypie filtering: how to do a comprehensive search 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 like to combine the request into one parameter. For example, I want to return objects containing the word "test" filtering from the comment field or the media_text field.

That would be perfect: http: mysite.com/api/v1/tagged? q = test

where 'q' executes an OR filter for both fields.

Is this doable?

UPDATE: this is what I work with advanced filters, but I'm not sure how to get the 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  
+5
source share
2 answers

, build_filters, django Q AND/OR,

Tastypie

:

+4

Advanced Filtering, , . build_filters, , , , , , .

+1

All Articles