In my django app I have a model “Match”, linked to my model “User” with a foreign key. I also have a function that gives me a query_set of “live_matches” (matches that are currently played).
What I try to have is a query_set with all the users of the “live_matches”.
Here is my models.py:
class LiveMatchManager(models.Manager):
def get_query_set(self):
now = timezone.localtime(timezone.now())
queryset = super(LiveMatchManager, self).get_query_set()
return queryset.filter(match__date_start__lte=now, match__date_end__gte=now)
class Match(models.Model):
user = models.ForeignKey(User)
date_start = models.DateTimeField()
date_end = models.DateTimeField()
# Managers
objects = models.Manager()
live_matches = LiveMatchManager()
What I would like to have is a function that gives me a query_set of the users that are linked to a “live_match”, and I don’t find how to do that.
Thank you for your help.
1 Answer