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 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.