Friday 15 August 2014

Django ModelForm ImageField Upload not working with Mobile Devices -


I am using a django ModelForm on a model that includes an ImageField. I have included a generic version below, in which some details have been stripped for clarity. This plan is working fine for me and I am capable of uploading and displaying images without a problem model.

My problem with this case is that uploads are not working from mobile devices, I have tested on an iPhone 4, an iPad 2 and an Android phone. No device displays any errors and there is no error in the log, although the image fails to upload

Does anyone know if this may be the cause of the problem or if Is this a known problem with modelform and imagefield? I really want to continue using the modelform because I have a very similar model and it makes maintenance easier, but I'm looking at custom options at this point.

Google has not made any useful information so far, if one can understand this in the right direction, then it would be greatly appreciated.

My model looks like this (some areas have been removed for brevity):

  class myModel (models.Model): note = models.CharField (MAX_LENGTH = 2000) image = models.ImageField (upload_to = "room_images /") LAST_UPDATED = models.DateTimeField (auto_now = true)   

My ModelForm looks like this with a custom TextArea area: < Presenting the model form with something like this (object name is the thing NY has been converted into equivalent).

  & lt; Form id = "myForm" action = "{% url my_url%} param_one = {{object.pk}} & amp; param_two = {{anotherobject.pk}}" enctype = "multipartile / form-data" method = " Post "& gt; {% Csrf_token%} {{form.as_p}}  & Lt; / Form & gt;   

My view looks like this (again some stuff has been stripped for clarity):

  @login_required def object_edit (requested): object_id = Request.GET. ('Param_one', none) receives object2_id = request.GET.get ('param_two', none), then object_id: object = get_object_or_404 (myModel, P = object_id) if obejct.userprofile.user = request.user : Return HttpResponseForbidden () if object_id and object2_id = 'none': other_object = get_object_or_404 (OtherModel, P = object_id) and: other_object = OtherModel (object = object) if request.POST: form = myForm (request.POST, request. FILES, example = Other_object) if form.is_valid (): form.save ()    

< P> And, it seems that your problem comes from jQuery Mobile.

By default, Jqum will try to load pages through AJAX for better user experience and changes.

Apparently when you do the same post in the URL in Django and want to handle it manually, you must include

  
  & lt; Form id = "myForm"   

action = "{% url my_url%} param_one = {{object.pk}} & param_two = {{anotherobject.pk}}" enctype = "Multipurpose / Farm-Data" method = "Post" data-ajax = "false" & gt; & Lt ;! - Change is here - & gt; {% Csrf_token%} {{form.as_p}} & Lt; / Form & gt; From

To:

This describes the framework to reload the whole page to clear Ajax hash in the URL

I did not try myself, I just got information from searching.

No comments:

Post a Comment