0

I have defined these models,

class Header(models.Model):
    date1 = models.DateField()

class Details(models.Model):
    header = models.ForeignKey(Header),
    field1 = models.CharField(max_length=10),
    archive = models.FileField(upload_to='x')

is it possible to set archive so that the upload_to is set to details.field1 + header.date1: e.g. if header.date1 = 2012-04-28 and details.field1 = 'sample', the file testing.doc being uploaded automatically stored under MEDIA_ROOT/2012-04-28/sample/testing.doc.

1 Answers1

1

If you read the Django documentation (here: https://docs.djangoproject.com/en/1.4/ref/models/fields/#django.db.models.FileField.upload_to) you will notice that upload_to can be a callable (that is a function) that takes two arguments, instance and filename

Claude Vedovini
  • 2,421
  • 21
  • 19