我編碼在Django的大型體育聯盟。我有單獨的體育,團隊,學校和時間表。時間表模型包括主頁和離開分數。這是一個基於結果的應用程序,而不是調度程序。寫一個體育聯盟計劃「Django的方式」
我的問題是關於記錄結果「Django的方式」。我可以創建節約勝損失結果的模式,但感覺就像存儲不必要的數據,如果兩個用戶爲同一遊戲不同的提交分數可能是一個問題。另一種方法是使用查詢並在每次調用時計算獲勝/失敗。
我準備好迎接挑戰,但我擔心,我會開始走向死衚衕去。這裏是我的模型,如果有幫助:
from django.db import models
from django.contrib import admin
class Sports(models.Model):
sport = models.AutoField(primary_key=True)
sport_name = models.CharField(max_length=225, blank=True, null=True)
class Meta:
managed = True
db_table = 'sports'
def __str__(self):
return self.sport_name
class School(models.Model):
school = models.AutoField(primary_key=True)
school_name = models.CharField(max_length=225, blank=True, null=True)
class Meta:
managed = True
db_table= 'school'
def __str__(self):
return self.school_name
class SchoolAdmin(admin.ModelAdmin):
fields = ('school_id', 'school_name')
class Teams(models.Model):
team = models.AutoField(primary_key=True)
team_name = models.CharField(max_length=225, blank=True, null=True)
sport_id = models.ForeignKey(Sports, models.DO_NOTHING, blank=True, null=True)
division = models.CharField(max_length=225, blank=True, null=True)
school = models.ForeignKey(School, models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = True
db_table = 'teams'
def __str__(self):
return self.team_name
class Schedule(models.Model):
match = models.AutoField(primary_key=True)
match_date = models.DateField(blank=True, null=True)
home = models.ForeignKey(Teams, related_name='home_set', blank=True, null=True)
away = models.ForeignKey(Teams, related_name='away_set', blank=True, null=True)
home_score = models.IntegerField(blank=True, null=True)
away_score = models.IntegerField(blank=True, null=True)
class Meta:
managed = True
db_table = 'schedule'
def __str__(self):
return '%s at %s' % (self.away, self.home)
class ScheduleAdmin(admin.ModelAdmin):
model = Schedule
list_display = ('match_date', 'home', 'away', 'home_score', 'away_score')