124👍
✅
if test.sound.name:
print "I have a sound file"
else:
print "no sound"
Also, FileField
‘s boolean value will be False when there’s no file: bool(test.sound) == False
when test.sound.name
is falsy.
0👍
According to this answer from a different question, you can try this:
class MyModel(models.Model):
name = models.CharField(max_length=50)
sound = models.FileField(upload_to='audio/', blank=True)
def __nonzero__(self):
return bool(self.sound)
- [Django]-How can I check the size of a collection within a Django template?
- [Django]-When to create a new app (with startapp) in Django?
- [Django]-Set Django's FileField to an existing file
Source:stackexchange.com