I'm implementing a search feature where I'm matching keys from the description. and also matching media if description and media type of
['mp4','mkv','mov','avi']
match so the condition is satisfied.So I have tried many methods but didn't find an efficient way. to make it possible without for loop.
I want to use those together.
- description and media type
['mp4','mkv','mov','avi']
postinlang_queryset = PostInLanguages.objects.filter(description__contains=search_name) media_type_query_set = LanguageMedia.objects.filter(content_type__contains ['mp4','mkv','mov','avi'])
- description and media type
Asked
Active
Viewed 86 times
1

Zain Jack
- 27
- 4
1 Answers
1
yes, it's possible without for loop.Just follow the following script:
postinlang_queryset = PostInLanguages.objects.filter(description__contains=search_name)
media_type_query_set = LanguageMedia.objects.filter(content_type__in=['mp4','mkv','mov','avi'])
N.B: content_type__in=['mp4','mkv','mov','avi']
If we pass an empty list then it will never throw exceptions but return empty queryset

Imam Hossain Roni
- 584
- 6
- 12
-
OK, Thanks dude, actually I wanted to use to together like `PostInLanguages.objects.filter(description__contains=search_name, LanguageMedia.objects.filter(content_type__in=['mp4','mkv','mov','avi']))` – Zain Jack Nov 22 '22 at 09:10
-
Could you please share the code for `PostInLanguages` & `LanguageMedia` models? – Imam Hossain Roni Nov 22 '22 at 09:15
-
OK, [here You can find](https://linkode.org/#gJuFOpxrQ5Qhq9ZcTPusn1) – Zain Jack Nov 22 '22 at 09:32