Ok, I get what what you're saying, but I seem to be having a heck of a time 
getting the randDir passed into the instance to perform the upload.

Here is the new code snippets:

views.py
instance = Upfile( file = file)
instance.upload(randDir)

models.py

@staticmethod
def upload(randDir)
   file = models.FileField( upload_to = MEDIA_ROOT+'/'+randDir)

I am using @staticmethod as I found that otherwise I needed to pass "self" 
and kept getting a NameError "self" not defined.

The error I currently get with the above code is:

TypeError: 'file' is an invalid keyword argument for this function

When clicking my "upload" button.

Thanks


On Sunday, November 24, 2013 10:31:34 AM UTC-5, Michael Manfre wrote:
>
> There are two things that you'll need to do. Set the random directory name 
> on the UpFile instance in the view and define a function to use with 
> upload_to that uses the random directory name on the instance to define the 
> file's target path.
>
>
> https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to
>
> Regards,
> Michael Manfre
>
> On Saturday, November 23, 2013 10:33:59 AM UTC-5, Matt Lind wrote:
>>
>> So I am trying to modify django-jfu ( a multi uploader) to send files to 
>> a unique directory for every unique upload session performed.  This is just 
>> due to my application's requirements and to prevent file collisions during 
>> the operations later down the road in my app.
>>
>> Anyway, here is views.py (I think the most relevant portion anyway, I 
>> could be wrong)
>>
>> def upload( request ):
>>
>>     # The assumption here is that jQuery File Upload
>>     # has been configured to send files one at a time.
>>     # If multiple files can be uploaded simulatenously,
>>     # 'file' may be a list of files.
>>     #Create the file object
>>     file = upload_receive( request )
>>
>>     #Create an instance of our Uploader Class and pass it the file object
>>     instance = UpFile ( file = file )
>>     #Save the file object
>>     instance.save() 
>>
>> And the "UpFile" class in models.py:
>>
>> class UpFile(models.Model):
>>     file = models.FileField( upload_to = 
>> MEDIA_ROOT+'/'+"".join([random.choice(string.ascii_letters) for n in 
>> xrange(12)]))
>>
>> The problem I am having is that it appears that the "random" section at 
>> the tail end of the "upload_to" option in models,py is processed only once 
>> when the server is started (or restarted).
>>
>> This won't work for my particular application, as I need the "top level" 
>> for any uploaded of a set of files to be unique.
>>
>> For example if I have the following "upload sessions"
>>
>> Session 1:  User only uploaded a single file.  A new random/unique 
>> directory should be generated under MEDIA_ROOT, and the file should be 
>> placed in that directory.
>> Session 2:  User uploaded 2 files.  A new random/unique directory should 
>> be generated under MEDIA_ROOT, and BOTH files should be uploaded to that 
>> directory (NOT a different directory per file)
>> Session 3:  User uploaded 100 files.  Like session 2 above, a new 
>> random/unique directory should be generated under MEDIA_ROOT and all 100 
>> files should be placed underneath.
>>
>> Later on I plan on cleaning house, but for now simply getting that logic 
>> down will get me moving again...
>>
>> Thanks for any help you can provide.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dfbe4f18-8195-4242-acc7-eb505798f82f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to