Hi Monte,
You can use a model from one app in another app.
So, let's say that in competitors/models.py (where you define the models for your "competitors" app), you have a model class named Participant. This model represents, well, a participant in the tournament. It is likely, as you stated, that you would need the Participant model (from the "competitors" app) in your "scoreboard" app when calculating scores for various participants.
In this case, all you have to do is import the Participant model from competitors/models.py into your scoreboard/models.py file. This way, you can create relationships between the different models of the various apps of your tournaments project.
So, assuming that you have a Score model in your scoreboard/models.py (which you use to tie scores to a particular Participant), you can approach it like this:
> Make sure you have defined the Participant model in your competitors/models.py file.
For example, in your competitors/models.py, you may have:
class Participant(models.Model):
name = models.CharField(max_length=90)
team_name = models.CharField(max_length=75)
signup_date = models.DateTimeField(auto_now_add=True)
# Add other fields here
> In your scoreboard/models.py file, you may have something like:
from django.db import models
from competitors.models import Participant
#Add other imports from other files and apps' models that you need here
class Score(models.Model):
participant = models.ForeignKey(Participant)
field_x = models.CharField(max_length=123)
another_field = models.PositiveIntegerField()
This way, when you query for scores through the Django ORM, the ORM also ties in the Participant from this queried score. You can then ask to get more info about the Participant from the participants table in the database.
So, when you execute a query through the ORM, for example:
participant_a_scores = Score.objects.filter(participant__name="Monte")
To get the name of this team name of the participant whose scores you just queried for, you do:
monte_team = participant_a_scores.participant.team_name
This query hits the "scores" table as well as the "participants" table to retrieve the score and the related Participant's info.
You may want to take a look at how Django handles relationships between models. Please, note that there is no difference in whether the related models are in the same app or from different apps. For details, please, take a look at documentation on:
If I made it more confusing, please, let me know.
The best way to clear the fog on this is to go through the official tutorial, the model relationship docs (in the above link) and to implement these in your own project.