Hello everybody,
I'm developing an app for the first time with Django and I have a problem with upload path and UUID.
I have a form with 3 fields for uploading text files. So I want to save those 3 files in the same directory which have a unique name. First I did this a big random number but if 2 requests are submitted almost at the same time I could generate the same number for those 2 which is not good. So I tried with the UUID method. To do so, I put a extra field in my model for the UUID which I generate in my controller at submission. Now I have a problem, how can I get the value of the UUID field to use it in the upload_to value of the FileField ?
Here is my Model :
class Analysis(models.Model):
uuidDir = models.CharField(max_length = 36)
dirFile = 'documents/%Y/%m/%d/' + str(uuidDir) #??
structureFile = models.FileField(upload_to = dirFile)
aliphFile = models.FileField(upload_to = dirFile)
vdwFile = models.FileField(upload_to = dirFile)
distGlyc = models.FloatField()
defaultType = models.CharField(max_length = 8)
outputName = models.CharField(max_length = 10)
Is there a method that I can call on my uuidDir field to get his value or am I thinking completely wrong on this ?
Thanks in advance for any help !
Amélie.