所以,我试图用我的数据创建一个数据透视图,但我不断得到“NoneType”对象不可迭代。我正在使用 Chartit。我的错误特别是'terms':['tot_ft']}])这特别是在数据透视图部分
这是我的代码:这是我导入的以下内容:
from django.shortcuts import render, get_list_or_404, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from basketball.models import Stats, Player, League, Game, Team
from django.contrib.auth import get_user
from django.db.models import Sum
from django.http import HttpResponse, HttpResponseRedirect
from django.core.mail import send_mail, BadHeaderError
from chartit import PivotDataPool, PivotChart
视图.py
def player_pivot_chart_view(request):
# Step 1: Create a PivotDataPool with the data we want to retrieve
playerPivotData = PivotDataPool(
series =
[{'options': {
'source': Stats.objects.all(),
'categories': 'player__first_name'},
'terms': {
'tot_ft':Sum('freeThrowsMade')}}])
pivcht = PivotChart(
datasource = playerPivotData,
series_options = [
{'options': {
'type': 'column',
'stacking': True},
'terms': ['tot_ft']}])
return render(request,'basketball/StatsPage.html', {'dataChart':pivcht})
模型.py
class Stats(models.Model):
player = models.ForeignKey(Player)
game = models.ForeignKey(Game)
freeThrowsMade = models.PositiveIntegerField(verbose_name='FTm', default = 0)
freeThrowsAttempted = models.PositiveIntegerField(verbose_name='FTa', default = 0)
twoPointsMade = models.PositiveIntegerField(verbose_name='2Pm', default = 0)
twoPointsAttempted = models.PositiveIntegerField(verbose_name='2Pa', default = 0)
threePointsMade = models.PositiveIntegerField(verbose_name='3Pm', default = 0)
threePointsAttempted = models.PositiveIntegerField(verbose_name='3Pa', default = 0)
blocks = models.PositiveIntegerField(default = 0)
steals = models.PositiveIntegerField(default = 0)
assists = models.PositiveIntegerField(default = 0)
fouls= models.PositiveIntegerField(default = 0)