If you just want to upload some files you might do something like the
following. The save function uses plain python to save the files to the
FILE_UPLOAD_DIR you defined in your setting file. You can play around with
the file names as much as you want here.
Question: Why a random name?
Vincent
class Application_files(forms.Form):
cv = forms.Field(label = 'CV *', widget = forms.FileInput(),
help_text="pdf or Word document")
paper = forms.Field(label = 'Paper *', widget = forms.FileInput(),
help_text="pdf or Word document")
def save(file,key,user,ext,overwrite=True):
if ext in ['pdf','doc']:
f = open('%s%s_%s.%s' %
(settings.FILE_UPLOAD_DIR,key,user,ext,),'wb')
f.write(file)
f.close()
def apply(request):
if request.POST:
for i in request.FILES.keys():
ext = request.FILES[i]['filename'][-3:].lower()
file = request.FILES[i]['content']
save(file,i,request.user,ext.lower())
else:
form = Application_files()
return render_to_response('apply/apply.html',{'form':form,})
On 6/26/07 10:43 PM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote:
>
> On 6/25/07, rob <[EMAIL PROTECTED]> wrote:
>>
>> We upload all of our images via the Admin app and would like all
>> uploaded images to be renamed to a set of numbers. We can generate the
>> random numbers fine, but is there an easy way to rename the file once
>> it's uploaded in the Admin app?
>
> Not at present. You would need to write a customized FileField to
> implement this sort of behaviour.
>
> Yours,
> Russ Magee %-)
>
> >
--
Vincent R. Nijs
Assistant Professor of Marketing
Kellogg School of Management, Northwestern University
2001 Sheridan Road, Evanston, IL 60208-2001
Phone: +1-847-491-4574 Fax: +1-847-491-2498
E-mail: [EMAIL PROTECTED]
Skype: vincentnijs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---