Note that there are some explanatory texts on larger screens.

plurals
  1. POsent image data using jquery ajax won't be saved using ModelForm
    primarykey
    data
    text
    <p>I'm going to edit an ImageField using jquery ajax,so I've used <code>jquery form plugin</code>,this is the code:</p> <pre><code>&lt;form id='form_upload' action="." method="POST" enctype="multipart/form-data"&gt; &lt;input type='file' id='id_HeadImage' name='id_HeadImage' /&gt; &lt;/form&gt; &lt;script typr="text/javascript"&gt; var options = { dataType: 'xml', url: '{% url DrHub.views.editNews param1,param2 %}', } $('#form_upload').ajaxSubmit(options); &lt;/script&gt; </code></pre> <p>in <code>&lt;head&gt;</code>:</p> <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"&gt;&lt;/script&gt; &lt;script src="http://malsup.github.com/jquery.form.js"&gt;&lt;/script&gt; </code></pre> <p>and in server side :</p> <pre><code>if ('id_HeadImage' in request.FILES) and (request.FILES['id_HeadImage']): gForm=GalleryForm(request.POST,request.FILES,instance=newsInstance.gallery_ptr) if gForm.is_valid(): gForm.save() </code></pre> <p>as U can see I'm going to edit ImageField of a model named Gallery. How can I do this?</p> <p>this is Gallery Model:</p> <pre><code>class Gallery(models.Model): HeadImage = models.ImageField(upload_to="gallery",blank=True,null=True) </code></pre> <p>While <code>gForm.is_valid()</code> returns <code>True</code>,but It won't be saved and Image of <code>HeadImage Field</code> won't be changed.</p> <p><strong>Note</strong> : I've checked this in firebug and I'm sure that data is sent and request.FILES has value.</p> <p>what's wrong here?</p> <p><strong>EDIT</strong> : I've worked based on this article: <a href="http://www.laurentluce.com/posts/upload-to-django-with-progress-bar-using-ajax-and-jquery/" rel="nofollow">http://www.laurentluce.com/posts/upload-to-django-with-progress-bar-using-ajax-and-jquery/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload