Background: I'm am creating Django app to manage receipts. The user will create a new Receipt
, fill out some fields with information on the receipt (i.e. cost, items, date purchased, etc.), and upload a copy of the receipt for storage.
Problem: I want to store the receipt *.pdf files in a folder based on the purchase date the user enters, however, I do not have access to self.date.strftime('%Y %B')
until after instantiation.
Example Code:
class Receipt(models.Model):
date = models.DateField()
item = models.CharField(max_length=128)
scan = models.FileField(upload_to='scans/{d}/'.format(d=date.strftime('%Y %B')),
max_length=100)
Research:
This SO question needs to do something similar, but for a different reason. The answer that he got, was this it was not possible without overriding the save()
method. How would that work with file uploads?
This SO question specifically addresses how to set the parameters of FileField
with a function; however, it does not involve using fields from the not-yet-complete model (i.e. Receipt
).
What are my work-around options?