Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:51+00:00 2026-05-21T07:24:51+00:00

I am using Django. I have a Fixture model, which looks something like: class

  • 0

I am using Django. I have a Fixture model, which looks something like:

class Fixture(models.Model):
    home_team = models.ForeignKey(Team, related_name="home_fixture_set")
    home_score = models.IntegerField(max_length=2, blank=True, null=True)
    away_team = models.ForeignKey(Team, related_name="away_fixture_set")
    away_score = models.IntegerField(max_length=2, blank=True, null=True)
    when = models.DateTimeField()

I have a Team model that looks something like:

class Team(models.Model):
    name = models.CharField(max_length=60)
    club = models.ForeignKey(Club)

I am able to access a list of “home” fixtures for a specific team through the home_fixture_set related_name:

my_team.home_fixture_set.all()

I can access the “away” fixtures similarly. However, I do not know how I combine the two and get the list of all fixtures this team is involved in? Eg:

my_team.home_and_away_fixture_set.all()

Note that home_and_away_fixture_set must return a queryset, so that I can filter on it:

my_team.home_and_away_fixture_set.filter(when__lte=datetime.datetime.now())

Is it possible to do this through the model query API? If not, is it possible to accomplish this reasonably easily through a Manager.raw() query?

Thanks
Jay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:24:51+00:00Added an answer on May 21, 2026 at 7:24 am
    from django.db.models import Q
    home_and_away_fixtures = Fixtures.objects.filter(Q(home_team=team)|Q(away_team=team))
    

    or edit:

    home_and_away_fixtures = my_team.home_fixture_set.all() | my_team.away_fixture_set.all()
    

    thx shadfc: single query as well

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django/apache/sqlite3 and I have a django model that looks like this: class
With Django I have this model: class downloads(models.Model): date = models.CharField(max_length=50) ip = models.ForeignKey(IPaddress)
I have the following models defined: class Team(models.Model): Name = models.CharField(max_length=250) class Fixture(models.Model): HomeTeam
I had the following idea: Say we have a webapp written using django which
I want to generate a list using my django model say I have these
I have been using django to write a rather complicated object-oriented model for a
I am using django and I have a file named models.admin.py and I want
I am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
I have a django model (A) which has a ManyToManyField (types) to another model
I'm using django, and have a static webpage with a GET form, and about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.