Open Wiper-R opened 2 years ago
From tortoise.expression import Q
filters = [Q(Q(recipients__id=user_1.id) & Q(recipients__id=user_2.id))]
await Channel.filter(*filters)
Would the above not work?
It's hard to say what's the exact issue because there is no actual code but I tried the following with the latest version and it seems to work in the same way as Django:
user1 = await User.create(username="1")
user2 = await User.create(username="2")
channel = await Channel.create(name="test")
await channel.recipients.add(user1, user2)
channels = await Channel.all().filter(recipients__in=[user1, user2])
print(channels)
prints [<Channel: 1>, <Channel: 1>]
I tried so many times but can't get it working.. I was expecting tortoise to be same like django-orm but it is not acting like that.
My Models
Now I am having two recipients
A
andB
and I want to filter channel which contains both recipients A and B. I tried using nested filter functions but it doesn't seem to work... While in django-orm it works perfectly.Is there any way to achieve this? Or I have to write custom queries for that?