Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/10/2013, 16:07
Avatar de Master_raven
Master_raven
 
Fecha de Ingreso: junio-2008
Ubicación: Guatemala City, Guatemala, Guatemala
Mensajes: 95
Antigüedad: 15 años, 10 meses
Puntos: 3
Carga multiple de archivos

tengo un problema con la carga múltiple de archivos

modelo
Código Python:
Ver original
  1. class ConversationReply(models.Model):
  2.     mensaje      = models.TextField()
  3.     user_reply   = models.ForeignKey(User, null=False)
  4.     ip_address   = models.IPAddressField()
  5.     time         = models.DateTimeField(auto_now_add=True)
  6.     conversation = models.ForeignKey(Conversation, null=False)
  7.  
  8. class ConversationFiles(models.Model):
  9.     conversationreply   = models.ForeignKey(ConversationReply, null=False)
  10.     archivo             = models.FileField(upload_to=upload_to, storage=s3, null = False, blank = False)

views
Código Python:
Ver original
  1. def send_mensaje(request, method):
  2.     u = request.user
  3.  
  4.     if method == 'reply':
  5.         mensaje = Conversation.objects.filter(user_two = u, id = request.POST['mensajeid']).get()
  6.  
  7.         if mensaje:
  8.             mconver = ConversationReply(
  9.                 mensaje = request.POST['wysiwyg-editor-value'],
  10.                 user_reply = u,
  11.                 ip_address = '192.168.1.1',
  12.                 time = datetime.datetime.now(),
  13.                 conversation = mensaje
  14.             )
  15.             mconver.save()
  16.            
  17.             if request.FILES:
  18.                 for f in request.FILES.getlist('attachment'):
  19.                     file = request.FILES('attachment')[f]
  20.                     files = ConversationFiles()
  21.                     files.conversationreply = mconver
  22.                     files.archivo = file
  23.                     files.save()
  24.  
  25.             mensaje.user_two = mensaje.user_one
  26.             mensaje.user_one = u
  27.             mensaje.time = datetime.datetime.now()
  28.             mensaje.is_read = False
  29.             mensaje.save()
  30.     elif method == 'new_inbox':
  31.         return ''
  32.  
  33.     return HttpResponseRedirect('/account/mensajes/')

vista
Código Python:
Ver original
  1. <form action="{% url "app.account.views.send_mensaje" "reply" %}" method="post" id="conversation-message-form" class="hide form-horizontal col-xs-12" enctype="multipart/form-data">
  2.     {% csrf_token %}
  3.     <input type="hidden" name="mensajeid" value="{{ mensaje.id }}" />
  4.     <div class="">
  5.         <div class="form-group">
  6.             <label class="col-sm-3 control-label no-padding-right">
  7.                 <span class="inline space-24 hidden-480"></span>
  8.                 Mensaje:
  9.             </label>
  10.  
  11.             <div class="col-sm-9">
  12.                 <div id="wysiwyg-editor" class="wysiwyg-editor"></div>
  13.             </div>
  14.             <textarea name="wysiwyg-editor-value" class="hide" id="wysiwyg-editor-value"></textarea>
  15.         </div>
  16.  
  17.         <div class="hr hr-18 dotted"></div>
  18.  
  19.         <div class="form-group no-margin-bottom">
  20.             <label class="col-sm-3 control-label no-padding-right">Adjuntado:</label>
  21.  
  22.             <div class="col-sm-9">
  23.                 <div class="form-attachments">
  24.                     <input type="file" name="attachment" />
  25.                     <input type="file" name="attachment" />
  26.                     <input type="file" name="attachment" />
  27.                 </div>
  28.             </div>
  29.         </div>
  30.  
  31.         <div class="align-right">
  32.             <button type="button" class="btn btn-sm btn-danger id-add-attachment">
  33.                 <i class="icon-paper-clip bigger-140"></i>
  34.                 Agregar Ajunto
  35.             </button>
  36.             <button type="submit" class="btn btn-sm btn-primary no-border" onclick="$('#wysiwyg-editor-value').val($('#wysiwyg-editor').html())">
  37.                 <span class="bigger-110">Responder</span>
  38.                 <i class="icon-arrow-right icon-on-right"></i>
  39.             </button>
  40.         </div>
  41.  
  42.         <div class="space"></div>
  43.     </div>
  44. </form>

el problema es que no guarda el archivo, les agradecería mucho su ayuda.
__________________
<?APRENDIENDO