Mostrar file widget del admin en el form input de template
from django import forms from django.contrib.admin.widgets import AdminFileWidget
class AgregarGuiaForm(forms.Form): year = forms.CharField() file = forms.FileField(widget=AdminFileWidget)
#views.py
<span style="color: #0000aa">try</span>:
<span style="color: #00aaaa">file</span> = guide.get_file().file
<span style="color: #0000aa">try</span>:
f = SimpleUploadedFile(<span style="color: #00aaaa">file</span>.name, <span style="color: #00aaaa">file</span>.read())
f.url = <span style="color: #00aaaa">file</span>.url
file_data = {<span style="color: #aa5500">'file'</span>: f}
<span style="color: #0000aa">except</span>:
messages.error(request,<span style="color: #aa5500">"archivo no existe %s"</span> % <span style="color: #00aaaa">file</span>.url)
file_data = {}
<span style="color: #0000aa">except</span>:
messages.error(request,<span style="color: #aa5500">"No existe archivo para esta guia"</span>)
form1 = AgregarGuiaForm({<span style="color: #aa5500">'year'</span>: guide.year}, file_data)
#output: http://img225.imageshack.us/img225/6347/screenshot1qz.png