Django FileField default file

brsbilgic picture brsbilgic · Jul 19, 2011 · Viewed 13.8k times · Source

I have a model which contains FileField as below

class Employer(models.Model):
        logo = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to='logos')

The question is how can I add a default file like "{{ MEDIA_ROOT}}/logos/anonymous.jpg" to this filefield ?

Answer

rolling stone picture rolling stone · Jul 19, 2011

You can specify the default file to use for that field as follows:

class Employer(models.Model):
        logo = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to='logos', default='settings.MEDIA_ROOT/logos/anonymous.jpg')