On Nov 5, 3:54 pm, Peter Bailey <[EMAIL PROTECTED]> wrote:
> I want to create a form for a large object that has numerous non-
> mandatory fields. I am still learning django, and am missing something
> easy I hope. All the examples and docs I see say to redirect after the
> form is posted and saved to the db (in my case). What I want is to
> leave the form up after the initial post, and allow a user to say, add
> 3 more field entries and re-save, etc. This is to handle a use case of
> when they are working on some data entry, want to save a partially
> done page, and then either leave it up and continue at their leisure
> or also come back and choose the object again and fill some more of
> the info in (I guess those are really 2 use cases!).
>
> This is a fairly common way of doing things in many of the business
> sites I have worked on, but I cannot find much discussion on it or
> documentation regarding it. Can anyone point me at some examples of
> this type of usage or suggest an alternative. I am starting to wonder
> if I am trying to bend the framework the wrong way, and maybe I need
> to rethink my design.
>
> Thanks for any feedback or help. It will be greatly appreciated. This
> is an amazing framework but it is taking me a while to learn some of
> the ins and outs. Must be from all those years of MS web programming
> that have clouded my brain!
>
> Cheers,
>
> Peter

There's nothing to say you shouldn't redirect back to the same page,
or a version of it. The point of the redirect is simply to remove the
possibility that the user would re-post the data if they pressed Back.

Presumably, you have an 'add' page where the users create the original
data. Once that is submitted, you'll need a page they can go to edit
existing data. So, to use the same model as the built-in admin site,
you'd have /mymodel/add/ and /mymodel/x/, where x is the PK of the
existing instance. So all you want to do is, on save redirect to the
'edit' screen. In your view:
if form.is_valid():
    obj = form.save()
    return HttpResponseRedirect('/mymodel/%s/' % obj.pk) # or better,
use a URL reverse function

You might want to do some checking of the POST first to see if they've
chosen a button that allows them to continue editing, rather than
quit.

Now I've written this, I've realised this is *exactly* what the admin
site does with the 'Save and continue editing' button - you might want
to look in django.contrib.admin.views for some clues as to how this
works.

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