On Sep 10, 9:50 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi
>
> I'm having a problem with inline formsets containing file field, i've
> had a good google but couldn't find an answer, so apolgies if this is
> a stupid or repetative question.
>
> I have a model Applicatant, which has a one to many relation with
> Education which contains a filefeild. My problem is that when django
> comes to validate the inline form education it reports that the field
> is empty, if i tell the model to allow empty feilds then the file is
> not saved
>
> Is it possible to use file fields with the inlineformset_factory or do
> i need to go at this another way?
>
> I have included my code, pretty simple and pretty much copied from the
> documentation:
>
> def myview(request):
>     InlineFormSet = inlineformset_factory(Applicant, Education)
>     applicant = Applicant.objects.get(pk=1)
>     if request.method == 'POST':
>         formset = InlineFormSet(request.POST, request.FILES,
> instance=applicant)
>         if formset.is_valid():
>            Do stuff
>    else:
>        formset = InlineFormSet(instance=applicant)
>
>    return render_to_response("mytemplate.html", { "formset":
> formset,})
>
> where mytemplate.html is simply
>
> <form action="./do" method="POST">
>
>     {{ formset.management_form }}
>     <table>
>         {% for form in formset.forms %}
>         {{ form.as_ul }}
>         {% endfor %}
>     </table>
>
>     <input type="submit" name="next" value="Next">
> </form>
>
> Many than ks
> Charlotte


The problem isn't with Formsets, it's just that you haven't set your
enctype in the HTML form element. It should be:
<form enctype="multipart/form-data" action="./do" method="POST">

See 
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to