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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -