views:

27

answers:

1

I have a model:

class Example(models.Model):
    unique_hash = models.CharField(max_length=32,unique=True)
    content = models.FileField(upload_to='source',blank=True,verbose_name="HTML Content File")

I would like to be able to set the content filename to default to a callable, but I don't see any way to have the callable reference unique_hash (or vice versa). Is this possible?

A: 

If you mean that callable should generate filename, I'm not aware of that.

You can, however, use custom storage (see docs, subclass django.core.files.storage.FileSystemStorage) that will provide custom algorithm for filename generation.

Almad
callable can generate a filename with default=callable
Adam Nelson
Darn, sorry, was not reading thoroughly. AFAIK, usual way to do defaults for fields as unqiue_hash is to overwrite `save()` method.
Almad