I made a small function, which, given the tuple, compares if all the elements in this tuple have the same sign.
For example, tuple = [-1, -4, -6, -8]good, but [-1, -4, 12, -8]bad. I'm not sure I made the smartest implementation, so I know this is the place to ask about.
def check_consistent_categories(queryset):
try:
first_item = queryset[0].amount
if first_item < 0:
for item in queryset:
if item > 0:
return False
return True
else:
for item in queryset:
if item < 0:
return False
return True
except:
return False
source
share