Take it easy.... You'll not make friends if people think you're
shouting...

This works for me with an ImageFile field. FileField should work the
same...

Template snippet:

    <form action="/electives/upload/" enctype="multipart/form-data"
method="post">
        <p>
            <label for="id_title">Title:</label> {{ form.title }}
        </p>
        <p class="datetime">
            <label for="id_postdate_date">Post date:</label> {{
form.postdate_date }} <label for="id_postdate_time">Post time:</label>
{{ form.postdate_time }}
        </p>
        <p>
            <label for="id_assoc_tags">Tags:</label> {{ form.assoc_tags
}}
        </p>
        <p>
            <label for="id_image_file">Image:</label> {{
form.image_file }} {{form.image}}
        </p>
        <p>
            <label for="id_body">Body:</label> {{ form.body }}
        </p>
        <p>
            <input type="submit" value="Save" class="default" />
        </p>
    </form>

And this view;
Post is the name of my model, be careful to not confuse it with POST.

def upload(request):
    # get all the content
    # for now, just assume a file is uploaded
    files = request.FILES
    for uploaded in files.keys():  # key is from <input type="file"
name="" />, ie image_file
        filedata = files[uploaded]
        filename = filedata['filename']
        content_type = filedata['content-type']
        content = filedata['content']
    body = request.POST.get('body', '')
    assoc_tags = request.POST.getlist('assoc_tags')
    title = request.POST.get('title', '')
    manipulator = Post.AddManipulator()   # Post is my model name
    new_data = request.POST.copy()
    new_data.update(request.FILES)        # definitely needed
    new_data['poster_id'] = str(request.user.id)   # following needed
to make sure manipulator.save passes off without a hitch
    new_data['poster'] = request.user.id
    new_data['slug'] = slugify(title)
    new_data['totalscore'] = 0
    new_data['image'] = filename                # this doesn't look
like it should work, does it?
    new_data['uuid'] = 'no data entered'
    manipulator.do_html2python(new_data)
    new_post = manipulator.save(new_data)
    return HttpResponseRedirect('/electives/')


Cheers,
Tone


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to