1
models.py我可以像这样在django模型中使用注释吗?
matches = models.ManyToManyField('Matches')
...
def get_rating(self):
from django.db.models import Sum, Value, IntegerField
from django.db.models.functions import Coalesce
return self.matches.annotate(rating=Coalesce(Sum('matches__rating_difference'), Value(0), output_field=IntegerField()) + Value(1000))
rating_difference
包含玩家等级分
get_rating
应该返回点的总和(玩家等级)
template.html
{{ player.matches.get_rating.(?)rating }}
什么是'in_matches'? –
你为什么不试试? (你可以做) – Justin
oops'in_matches' ==='matches' – 8bitard