Django ValueError“无法查询” asd“:必须是” OnlineGame“实例。

时间:2019-07-17 08:26:49

标签: django django-models django-views

我收到此错误; “无法查询“ asd”:必须是“ OnlineGame”实例。”

(asd是gameslug)(OnlineGame是存储在线游戏名称(如大声笑)的类)

models.py

class Game(models.Model):
      match=models.ManyToManyField(Match,related_name="gamematch")

class Match(models.Model):
      teams = models.ManyToManyField(Team, through='MatchTeam')

class MatchTeam(models.Model):
    match = models.ForeignKey('Match', on_delete=models.CASCADE)
    team = models.ForeignKey(Team, on_delete=models.CASCADE)
    rank = models.IntegerField(default=20)
    point=models.IntegerField(default=0)

views.py

    game=get_object_or_404(Game
            ,tournament__slug=tournamentslug
            ,slug=slug,game__slug=gameslug)

    teams = MatchTeam.objects.filter(
    match__game=game
).annotate(
    points=F('rank')
).order_by(
    '-broyale_match', 'rank'
)

1 个答案:

答案 0 :(得分:0)

我将match__game替换为match__game__tournament__slug = tournamentslug,然后奏效了