自定义计算返回不可调用的“ NoneType”对象

时间:2018-08-07 08:34:24

标签: django

我正在尝试为我的系统做一些计算,我需要像这样获取val res01 = sqlContext.sql(query2.toString) res01.coalesce(1).write.json("D:/result01") 的所有位置计数

superuser

然后我需要计算该用户的所有许可证,就像这样

location = LocationData.objects.filter(email=self.request.user.email).count()

我需要检查count = MyUser.objects.filter(location_count=self.request.user.email).count() == location并以一定价格到达count位置,

*

获得价格后,我需要将其显示在模板上。

完整的视图是

if count == location:
       context['social'] = location * FRISTPRICE

,完整错误为HERE,我的第一个猜测是无法返回上下文并且此计算效果不好,所以有人可以帮助我了解为什么我收到此错误,谢谢。

1 个答案:

答案 0 :(得分:2)

get_context_data如果用户不是超级用户,则不返回任何内容。取消缩进的返回上下文行可对其进行修复:

@cached_property
def get_context_data(self, **kwargs):
    context = super(AdminDashboard, self).get_context_data(**kwargs)
    user = MyUser.objects.get(pk=self.request.user.pk)

# check if user is superuser if not don't include him
    if user.is_superuser:
        # check how much locations does user have
        location = LocationData.objects.filter(email=self.request.user.email).count()

        # check how much user have licences payed for
        count = MyUser.objects.filter(location_count=self.request.user.email).count()

        # if count is == to location then the location is proper
        # so count * package = application sales
        if count == location:
            context['first_package'] = location * FIRSTPRICE

        if count == location:
            context['second_package'] = location * SECONDPRICE

        if count == location:
            context['third_package'] = location * THIRDPRICE

    return context