Reputation: 22489
how can i check if i have an empty column in my queryset?
this is my code :
mastercard_percent = ClientPaymentOption.objects.filter(name='MasterCard', client=client).values_list('itemcharged',flat=True)
if mastercard_percent == [None]:
print 'empty'
print mastercard_percent
and i got only this:
[None]
i try also in my code to become:
if mastercard_percent == [None]:
print 'empty'
print mastercard_percent
but it also print :
[None]
thanks in advance...
Upvotes: 4
Views: 4412
Reputation: 11341
What is the output of repr(mastercard_percent)
? If its value truly is [None]
, then a comparison with [None]
should work:
>>> a = [None]
>>> a == [None]
True
Upvotes: 0
Reputation: 41
Shouldn't the expression be like:
print 'empty' if mastercard_percent == []
print mastercard_percent
In case that you're looking for an empty list.
Upvotes: 0
Reputation: 21243
You have to check the values of the column
like if not mastercard_percent[0]: print 'empty'
Upvotes: 3