[Answer]-Unsupported operand type(s) for +: 'NoneType' and 'NoneType'

1👍

✅

Part of the problem is probably the if/elif logic. Remember that elif will only run if the first if statement registers as false. So, imagine this scenario:

check = 0
ind = None
team = None

In that scenario, the first that that happens is that carttotal gets set equal to 0. Then, since the first if was true (check was 0), the remaining elifs don’t run, and ind + team try get added even though they haven’t been changed from None.

There are more elegant ways to do this, but if you just change the elifs to ifs, it should work fine. There’s some redundancy there, though, and shorten the logic to by a few lines by using a tertiary operator

ind_query = signedup.objects.filter(sessionid = session)
ind = ind_query.aggregate(Sum ('price'))['price__sum'] if ind_query else 0

team_query = team_signup.objects.filter(sessionid = session)
team = team_query.aggregate(Sum ('price'))['price__sum'] if team_query else 0

carttotal = ind + team

Leave a comment