0
Django-tables2
과 관련된 이상한 문제가 있습니다. 두 개의 열, 즉 timestamp
및 description
이있는 간단한 테이블을 만들었습니다.Django-tables2는 첫 번째 행과 마지막 행을 렌더링합니다.
QuerySet
의 첫 번째 개체가 테이블에 렌더링되지 않는 것이 문제입니다. 첫 번째 개체 대신이 행에 마지막 개체가 복사됩니다.
Action
객체와이 테이블을 채우는거야.
모델
class Action(models.Model):
user = models.ForeignKey(User,on_delete=models.CASCADE,related_name='actions')
description = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u"{} - {} {}".format(self.user, self.timestamp, self.description)
VIEW 당신이 볼 수 있듯이, 나는 queryse를 인쇄 한
@decorators.is_authenticated_or_homepage
def dashboard(request):
print Action.objects.filter(user=request.user)
recent_actions_table = RecentActionsTable(Action.objects.filter(user=request.user))
context = {'user': request.user,
'recent_actions_table':recent_actions_table}
return render(request, 'main_app/dashboard/index.html', context=context)
표
class RecentActionsTable(tables.Table):
class Meta:
model = Action
fields = ('id','timestamp','description')
attrs = {'id': 'id_recent_actions_table',
'class': 'table', }
테이블을 만들기 전에 t :
<QuerySet [<Action: futilestudio - 2016-12-29 16:15:33.299000 New product created (6)>,
<Action: futilestudio - 2016-12-29 16:53:29.534000 Manual scan of product>,
<Action: futilestudio - 2016-12-29 17:05:38.215000 Manual scan of product>,
<Action: futilestudio - 2016-12-29 17:27:05.462000 New product created (7)>]>
첫 번째 개체가 테이블에 없습니다. 대신, ID가 5 인 복제 된 객체가 있습니다.
잘못된 아이디어가 있습니까?