Python 我可以这样在django模型中使用注释吗?如何使用?
models.pyPython 我可以这样在django模型中使用注释吗?如何使用?,python,django,django-models,django-templates,Python,Django,Django Models,Django Templates,models.py 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__ra
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))
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.aggregate(rating=Coalesce(Sum('rating_difference'), Value(0), output_field=IntegerField()) + Value(1000))
rating_difference
包含玩家评分点
get_rating
应返回积分总和(玩家等级)
template.html
{{ player.matches.get_rating.(?)rating }}
它工作正常 models.py
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))
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.aggregate(rating=Coalesce(Sum('rating_difference'), Value(0), output_field=IntegerField()) + Value(1000))
template.py
{{ player.matches.get_rating.rating_difference }}
它工作正常 models.py
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))
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.aggregate(rating=Coalesce(Sum('rating_difference'), Value(0), output_field=IntegerField()) + Value(1000))
template.py
{{ player.matches.get_rating.rating_difference }}
匹配中的
是什么?为什么不试试呢?(您可以这样做)oops中的匹配项
==匹配项
中的是什么
?为什么不试试呢?(您可以这样做)oops在匹配中
==匹配