当我列出点时,我想为用户添加所有点。在我的模板中,我只想调用类似“points.total_points”的名称。以下是我到目前为止所拥有的,如果可能的话,我想将这一切都保留在我的模型中。有人可以帮助解释如何实现这一目标吗?
谢谢
模型.py
class PointsManager(models.Manager):
def points_list(self,thisUser):
list = Points.objects.filter(user=thisUser)
return list
class Points (models.Model):
user = models.ForeignKey(User)
points = models.IntegerField(verbose_name=("Points"), default=0)
created = models.DateTimeField(("Created at"), auto_now_add=True)
updated = models.DateTimeField(verbose_name=("Updated at"), auto_now=True)
objects = PointsManager()
class Meta:
verbose_name = ('Point')
verbose_name_plural = ('Points')
视图.py
@login_required
def history(request):
thisPoints = Points.objects.points_list(request.user)
context = {'points':thisPoints}
return render_to_response('points/history.html', context, context_instance=RequestContext(request))