Here's the relevant parts of the model:

class Resource(models.Model):
    photo = ThumbnailerImageField(_("photo"),
        upload_to='photos', blank=True, null=True)

This works fine in admin and with regular form posts.

Trying to use jquery.post in one situation to post a photo without 
suffering a page reload.

With the regular post, the photo field returns like this (in 
form.cleaned_data):
'photo': <InMemoryUploadedFile: P1010058.JPG (image/jpeg)>

And request.FILES is like this:
<MultiValueDict: {u'photo': [<InMemoryUploadedFile: P1010058.JPG 
(image/jpeg)>]}>

With the jquery post, photo is None and the MultiValueDict is empty.  

In both cases the form is set up with enctype="multipart/form-data", 
and the form is instantiated in the view with 
form = ResourceForm(request.POST, request.FILES)

What am I doing wrong?

Here's the javascript:

$("#detailForm").submit(function(event) {
    event.preventDefault();

var $form = $( this ),
url = $form.attr( 'action' );

var formData = $form.serialize();
saveResource(url, formData); 

});

function saveResource(url, formData)
{
notifySaving();
var jqxhr = $.post( url, formData,
function( data ) {
$('#detailModal').modal('hide');
notifySaved();
resourceSaved = true;
})
.fail(function() 
{ 
$('#detailModal').modal('hide');
notifyProblem(); 
resourceSaved = false;
startRetrying();
}
);
}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to