I have a rather strange problem in Django, where I do not see how I could combine "__contains" and "__in" in a single statement.
So, here is my situation: I have a list of entries like so:
a = ["hgfjhgj89789jkbjk", "jhgjkhj89789jkhkjh", "jhgkjhkj89689gfghdfhg"]
and I would like to check this list against a queryset - which I would normally do like so:
queryset = MyModel.objects.all().filter(my_field__in=a)
However, in my situation, my_field
does not exactly match the values in a
and therefore, I am having to resort to __contains
like so:
queryset = MyModel.objects.all().filter(my_field__contains=a[0])
..but then, my a
has now 2000 entries, and I cannot run the above query 2000times - sounds silly.
So, how can I combine this "__contains" with "__in"? Sorry if this is a daft question!