I have a field in a model as follows:
class FirmwareUpload(models.Model):
firmware = models.FileField(upload_to="uploads/%A-%B-%Y")
...
If I do an upload through the Admin, everything works great, a
directory gets created with the strftime info filled in.
However, I need to use this with my own view, which currently looks as follows:
def upload_file(request):
manipulator = FirmwareUpload.AddManipulator()
if request.POST:
new_data = request.POST.copy()
new_data['firmware'] = _save_file(request.FILES['firmware_file'])
errors = manipulator.get_validation_errors(new_data)
if errors:
_nuke_file(request.FILES['firmware_file'])
print errors
return HttpResponseRedirect("error/")
else:
manipulator.do_html2python(new_data)
manipulator.save(new_data)
return HttpResponseRedirect("success/")
else:
form = forms.FormWrapper(manipulator, {}, {})
return render_to_response('firmware/upload.html', {'form':form},
context_instance=RequestContext(request))
def _make_path(info):
# XXX I need the strftime info here
return os.path.join(settings.MEDIA_ROOT, "uploads", info['firmware'])
def _save_file(info):
path = _make_path(info)
f = open(path, "wb")
f.write(info['content'])
f.close()
return os.path.join("uploads",info['firmware'])
def _nuke_file(info):
os.remove(_make_path(info))
Obviously though, doing this doesn't access the strftime info. What's
the "accepted" way (if any) of doing what I need to do? Even if
someone can point me in the direction of being able to access the
upload_to field, and then I can do the strftime myself (although
that's obviously a non-optimal solution)
Thanks in advance,
Jay P.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---