Hi all, I am creating a form ( a customized one ) which tries to
upload ( bind )
an image file and save the file into my directory ( and its location
in mysql database )

The code is right here :

# views.py
def customized_form(request):
    if request.method == 'POST':
        form = CustomizedForm(request.POST, request.FILES)
        if form.is_valid():
            # here create the data object
            pressrelease = PressRelease.objects.create(
                title = form.cleaned_data['title'],
                body = form.cleaned_data['body'],
                images = form.cleaned_data['images'],
                user = request.user,
            )
            pressrelease.save()
            return HttpResponseRedirect('/upload_form_success/')
    else:
        form = CustomizedForm()
    variables = RequestContext(request,{'form':form})
    return render_to_response('upload_form.html',variables)

#forms.py
class CustomizedForm(forms.Form):
    title = forms.CharField(max_length=100)
    body = forms.CharField()
    images = forms.FileField()


#models.py
class PressRelease(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
    images = models.ImageField(upload_to='userimages')
    user = models.ForeignKey(User)


#upload_form.html
<form method="post" action="." enctype="multipart/form-data">
        {{ form.as_p }}
<input type="submit" value="Submit">
</form>


After submitting the form, the mysql database gets populated with the
required data, including the
file name ( but not location )

I've check the 'userimages' folder and found out that none of the
uploaded images are
being saved into the 'userimages' folder.

Can any one guide me on how to upload files ( image files ) and save
it to a
directory and with it's location in the mysql database? I need to be
able to retrive the files as well.

PS: i understand i can do it by creating a form out of the model class
but i just
wanted to learn more about the forms api.

Thank you for your time!
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to