Answer the question
In order to leave comments, you need to log in
How to get records where IDs are inside an array?
Good day! There are two match objects, team
class Match(models.Model):
.....
class Team(models.Model):
match = models.ForeignKey(Match, related_name="command", on_delete=models.CASCADE)
.....
Answer the question
In order to leave comments, you need to log in
from django.models.db import Q
ids = [2, 6]
q = Q()
for id in ids:
q &= Q(command__id=id)
qs = Match.objects.filter(q).distinct()
from django.models.db import Q
Match.objects.filter(Q(command__id=arr[0]) & Q(command__id=arr[1])).distinct()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question