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

  • Home
  • SEARCH
  • 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 am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
Is it possible to have a variable number of fields using django forms? The
I'm using Google App Engine and Django templates. I have a table that I
As the title suggests, I'm using Google App Engine and Django. I have quite
Using Django's built in models, how would one create a triple-join between three models.
I am currently using Django to construct JSON encoded objects which a retrieved using
I can load the fixture file in my django application by using loaddata: manage.py
I'm using Django 1.0.2. I've written a ModelForm backed by a Model. This model
Using django-tinymce I have successfully embedded TinyMCE in the Admin before. Embedding it in
I have been using Django for web-development, and have become quite fond of that

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.