संभव डुप्लिकेट: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
मैं एक tastypie modelRseource है कि इस तरह दिखता है या फिल्टर के बीच ऑपरेटर और क्वेरी को एक पैरामीटर में गठबंधन करना पसंद करेंगे। उदाहरण के लिए, मैं उन वस्तुओं को वापस करना चाहता हूं जिनमें टिप्पणी फ़ील्ड या media_text फ़ील्ड से "परीक्षण" फ़िल्टरिंग शब्द शामिल है।
यह आदर्श होगा: http: mysite.com/api/v1/tagged q = परीक्षण
जहां 'क्यू' एक या दोनों क्षेत्रों के लिए फिल्टर करता है।
क्या यह करने योग्य है?
अद्यतन: यहाँ है कि मैं क्या उन्नत फ़िल्टर के साथ पर काम कर रहा हूँ, लेकिन वास्तव में यकीन है कि कैसे एक 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