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