2012-12-25 28 views
0

我試圖從表'points_points'列出頁面上的所有數據,其中user_id是用戶登錄的。但是,顯示時沒有數據列出時,該對象爲空。我100%在用戶的數據庫中有數據。爲什麼沒有顯示?任何人都可以發現下面的錯誤Django模型:使用過濾器獲取數據,爲空

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 %} 

回答

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 %}