I have a column in my table which is completely empty.
I want to implement some logic that says, if the field is empty then get the image from an API link. If it’s not empty then use the image available.
The field IS empty as shown when I open my database.
BUT when I implement this code:
if unipart.coverart is None:
print "yes"
else:
print "no"
It says ‘no’, indicating that the field is full.
Why doesn’t this work, and is there a better way to validate this information?
EDIT: OK just tried
if not unipart.coverart:
instead and that did the trick. Can someone explain why the first method didn’t work?
Blank
CharFields andTextFields are empty strings (''), notNone. So, you need to testunipart.coverart == ''.