python - Django - FileField check if None -
python - Django - FileField check if None -
i have model optional file field
class mymodel(models.model): name = models.charfield(max_length=50) sound = models.filefield(upload_to='audio/', blank=true)
let's set value
>>> test = mymodel(name='machin') >>> test.save()
why ?
>>> test.sound <fieldfile: none> >>> test.sound none false
how can check if there file set ?
if test.sound.name: print "i have sound file" else: print "no sound"
also, fieldfile
's boolean value false when there's no file: bool(test.sound) == false
when test.sound.name
falsy.
python django django-models
Comments
Post a Comment