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 7170545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:14:05+00:00 2026-05-28T15:14:05+00:00

this is my models.py from django.db import models # Create your models here. class

  • 0

this is my models.py

from django.db import models

# Create your models here.

class Leagues(models.Model):
    LeagueName = models.CharField(max_length=200)

class Team(models.Model):
    TeamName = models.CharField(max_length=200)

class LeagueTable(models.Model):
    league = models.ForeignKey(Leagues)
    team = models.CharField(max_length=200)
    matches_played = models.IntegerField()
    matches_won = models.IntegerField()
    matches_drawn = models.IntegerField()
    matches_lost = models.IntegerField()
    points = models.IntegerField()

class FixtureTable(models.Model):
    league = models.ForeignKey(Leagues)
    fixture_date = models.DateField('Fixture Date')
    team_one = models.CharField(max_length=200)
    team_one_score = models.IntegerField()
    team_two = models.CharField(max_length=200)
    team_two_score = models.IntegerField()

in the “class FixtureTable”, i want team_one and team_two to be linked to two differnt teams in “class Team” models. how to create multiple relations, or is it possible.

PS: this is purely a noob, with a little experience in programming, but no experience with either python or databases.

thankyou.

  • 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-28T15:14:06+00:00Added an answer on May 28, 2026 at 3:14 pm

    You can create as many ForeignKeys as you like to the same model. I suspect what’s tripping you up is Django giving you an error saying that you need to specify a related name.

    By default, Django creates an attribute on the opposite model of the form <model>_set. So in the following scenario:

    class FixtureTable(models.Model):
        team_one = models.ForeignKey(Team)
    

    Django would add a related manager to Team as fixturetable_set. If you then did:

    class FixtureTable(models.Model):
        team_one = models.ForeignKey(Team)
        team_two = models.ForeignKey(Team)
    

    Django would attempt to add the same attribute twice and obviously fail. The fix is to specify a related_name, so each can have a unique related manager:

    class FixtureTable(models.Model):
        team_one = models.ForeignKey(Team, related_name='team_one_fixturetables')
        team_two = models.ForeignKey(Team, related_name='team_two_fixturetables')
    

    Then, everything will work fine. You can specify whatever you like for related_name as long as it’s unique for the model.

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

Sidebar

Related Questions

Given this model: from django.db import models from django.contrib.auth.admin import User # Create your
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
In my models.py: from django.db import models from core import tasks class Image(models.Model): image
Consider the following django model from django.db import models from django.contrib import auth class
I've got a couple django models that look like this: from django.contrib.sites.models import Site
i have this code from t he django sample tutorial from django.db import models
I have a class Book : from django.db import models from users.models import User
from django.contrib.auth.models import User u = User.objects.get(username='test') user.password u'sha1$c6755$66fc32b05c2be8acc9f75eac3d87d3a88f513802 Is reversing this password encryption
I ran the code to create the generically related objects from this demo: http://www.djangoproject.com/documentation/models/generic_relations/
Say I've got a domain model created from C# classes like this: public class

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.