我正在尝试列出表'points_points'中页面上的所有数据,其中user_id是用户登录的。但是,当显示没有列出数据时,该对象为空。我100%在数据库中为用户提供数据。为什么没有显示?有人能发现下面的任何错误吗?
models.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')
views.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))
template.py
<h1>|{{ points }}|</h1>
{% for item in points.Points_items.all %}
<tr>
<td>{{ item.points }}</td>
</tr>
{% endfor %}
答案 0 :(得分:2)
试试这个
def points_list(self,thisUser):
return super(PointsManager, self).get_query_set().filter(user=thisUser)
您的模板看起来不对..
{% for item in points %}
<tr>
<td>{{ item.points }}</td>
</tr>
{% endfor %}