here is model
class Thing(models.Model):
        PID=models.ForeignKey(Property)
        name = models.CharField(blank=False, null=False, maxlength=30)
        photo = models.ImageField(upload_to='images/things/', blank=True,
null=True)
the form
class ThingForm(forms.Form):
    name = forms.CharField(max_length=30, required=True, label=_('Name
of the thing'))
    photo = forms.Field(widget=forms.FileInput, required=False,
label=_('Photo'))

html
<form action="/test" method="post" enctype="multipart/form-data">
<input type="file" name="photo" />

save data
        new_data = request.POST.copy()              # these two lines
are
        new_data.update(request.FILES)               # very important
        form = ThingForm(new_data)
        if form.is_valid():
            clean_data = form.clean_data
            t = Thing()
            t.name = clean_data['name']
            if clean_data['photo']:
                photo = clean_data['photo']
                t.save_photo_file(photo['filename'],
photo['content'])

you can also eliminate model and save directly to some binary stream


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