DJANGO Queryset filter using array values

DJANGO


How to filter django queryset using values from an array.

Standard functionality is to use __in

 

in

In a given iterable; often a list, tuple, or queryset. It’s not a common use case, but strings (being iterables) are accepted.

Examples:

Entry.objects.filter(id__in=[1, 3, 4])
Entry.objects.filter(headline__in='abc')

inner_qs = Blog.objects.filter(name__contains='Cheddar')
entries = Entry.objects.filter(blog__in=inner_qs)

inner_qs = Blog.objects.filter(name__contains='Ch').values('name')
entries = Entry.objects.filter(blog__name__in=inner_qs)


ztags = str(zcontent.doc_tags).replace(" ",'').split(",")
zdata_related = docu_lib.objects.filter(doc_tags__in = ztags)

 

Reference

https://docs.djangoproject.com/en/dev/ref/models/querysets/#in

            Related