我如何实现以下....
每次在模板中显示点对象时,都必须始终由当前用户过滤。所以,在模型中,我尝试了下面的代码。
这可能吗?我怎样才能实现上述目标?
模型.py
from django.db import models
from django.contrib.auth.models import User
POINTS_PENDING, POINTS_ADDED, POINTS_DEDUCTED, ORDER_PROCESSING = range(4)
STATUS_OPTIONS = (
(POINTS_PENDING, ('Pending')),
(POINTS_ADDED, ('Added')),
(POINTS_DEDUCTED, ('Deducted')),
(ORDER_PROCESSING, ('Processing')),
)
class PointsManager(models.Manager):
def points_list(self,User):
list = Points.objects.filter(points_user=User).exclude(status=ORDER_PROCESSING)
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()