Hi,
I'm doing a 2-step form, so that in the first step, the user will
upload an image, and in the second step, she will fill in some details
about it.

My problem is that after the second step, the data is not saved in the
model.

Here's some relevant code.

The model:

class Image(models.Model):
    uploaded = models.DateTimeField(editable=False)
    description = models.TextField()

    def save(self):
        self.uploaded = datetime.now()
        models.Model.save(self)

Two forms, one with an ImageField, and one connected to the Image
model:

class ImageUploadForm(forms.Form):
    file = forms.ImageField()

class ImageUploadDetailsForm(forms.ModelForm):
    class Meta:
        model = Image


The relevant views:

def image_upload_process(request):
    """Process the form"""

    form = ImageUploadForm(request.POST, request.FILES)
    if not form.is_valid():
        return render_to_response("image_upload.html", {"form":form})

    file = request.FILES["file"]
    s3_filename = str(uuid4()) + os.path.splitext(file.name)[1]
    store_image_in_s3(file, s3_filename)

    image = Image(filename = s3_filename)
    image.save()

    return render_to_response("image_upload_phase_2.html",
        {"image":image,
         "s3_images_bucket":settings.S3_IMAGES_BUCKET,
         "s3_url":settings.S3_URL,
         "form":ImageUploadDetailsForm(),
        },
        context_instance=RequestContext(request))

def image_upload_process_details(request):
    """Process the second part of the form"""

    form = ImageUploadDetailsForm(request.POST)
    image_id = request.POST.get('image_id')
    image = Image.objects.get(pk=image_id)

    if not form.is_valid():
        return render_to_response("image_upload_phase_2.html",
            {"image":image,
             "s3_images_bucket":settings.S3_IMAGES_BUCKET,
             "s3_url":settings.S3_URL,
             "form":form,
            },
            context_instance=RequestContext(request))

    return HttpResponseRedirect("/show/" + image_id)


As you can see, in the first of the two views, I take the uploaded
image from the request and save it to Amazon's S3. Then redirect to a
template that shows the second form (ImageUploadDetailsForm), plus an
hidden field with the Image's id.

After the second form is done and valid, I would like to save the
information that comes to it to Image, in the same row that has the id
I was passing.

How can I do this?

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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