87👍
✅
I found that the ImageField’s name is
u”, so is there any better way to do
it ?
Actually, it looks like that’s exactly how this class evaluates bool()
, so the better way is to just test its bool()
by calling if p.avatar
ImageFieldFile
subclasses File
, which defines:
def __nonzero__(self):
return bool(self.name)
So the better way is indeed:
if not p.avatar:
print "I don't exist"
bool(p.avatar) is False
Source:stackexchange.com