4

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...

3 Answers 3

3

You have to check the values of the column

like if not mastercard_percent[0]: print 'empty'

Sign up to request clarification or add additional context in comments.

Comments

0

Shouldn't the expression be like:

print 'empty' if mastercard_percent == []
print mastercard_percent

In case that you're looking for an empty list.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.