I manage to save the image,
first make sure to have :
<p><label for="id_image">picture: </label>{{form.image_file}} {{
form.image }} </p>
in your template
then the view :
--------------------
#post a form
def create_recette(request):
manipulator = recettes.AddManipulator()
#12 being image_fil , recettes.AddManipulator().fields
manipulator.fields[12].validator_list.append(isValideImageWeight)
manipulator.fields[11].validator_list.append(isValideImageWeight)
if request.POST:
# If data was POSTed, we're trying to create a new Place.
new_data = request.POST.copy()
# Check for errors.
errors = manipulator.get_validation_errors(new_data)
if not errors:
# that was the line to add
new_data.update(request.FILES)
# No errors. This means we can save the data!
manipulator.do_html2python(new_data)
new_recette = manipulator.save(new_data)
# Redirect to the object's "edit" page. Always use a
redirect
# after POST data, so that reloads don't accidently
create
# duplicate entires, and so users don't see the
confusing
# "Repost POST data?" alert box in their browsers.
return HttpResponseRedirect("/cefinban/recette/%i/" %
new_recette.id)
else:
# No POST, so we want a brand new form without any data or
errors.
errors = new_data = {}
# Create the FormWrapper, template, context, response.
form = formfields.FormWrapper(manipulator, new_data, errors)
return render_to_response('recettes/recettes_form', {'form': form})
--------------
BUT,
the validator for image is still not called, even if i upload a non
picture file it will not complain, even
if i make the validator to raise an error as follow
def isValideImageWeight(field_data, all_data):
raise validators.ValidationError, "!!!!!!RAISED!!!!!!"
so it is clear that no validator are called.
why ? how to make it work ? to finally have a working form including an
image field.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---