가능한 중복 :Tastypie에서 하나 개의 쿼리에 필터를 결합
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'], }
은 내가이 필요합니다 :
Django Tastypie Advanced Filtering: How to do complex lookups with Q objects
이 이상적 일 것이다 : HTTP : mysite.com/api/v1/tagged Q = 테스트 'Q'는 두 필드에 대한 OR 필터를 수행
.
이 것이 가능합니까?
업데이트 : 저는 여기에 고급 필터로 작업하지만, OR 문을 얻는 방법을 정말 잘 모르겠습니다하고있는 무슨이다 :
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
이것은 내가 필요한 것입니다. 감사! – bevinlorenzo