Re: Preview model before saving it

2009-10-22 Thread Aaron

On Oct 22, 1:41 pm, Ethan Jucovy  wrote:
> Do you need one-time previews ("are you sure you want to save this?") or
> real drafts that can be viewed more than once?  If you just need an
> intermediate preview step for the user who's submitting the data, you can do
> it without saving any data on the backend --

The general behavior I want is to have a page with the model form and
a "preview" link.  The preview link would open a page (likely a new
tab) that would display the model as it would appear on my web site.
That is, I have a template for each of my models, and I would like to
reuse those for rendering my preview objects, though I may have to add
an extra parameter to them to disable features only available to live
objects.

> write a "preview" view that validates the POSTed data without committing
>  and then
> renders a template with a form that includes that data by default, and which
> will POST to the real save view.
>
> I like to put the data in hidden fields, and render a representation of the
> previewed data separately.  That way the "save for real" form can just look
> like a button to the user, and you can have a separate form for modifying
> the data and going through the preview cycle again.
>
> I haven't done anything custom in the django admin, but I assume this
> technique can work there too.

That was the idea I had. I'd have a view that gets the ModelForm and
sends the (unsaved) model to the template. The trick is figuring out
how to get access to the ModelForm inside the view, especially when I
want to use the admin change form.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Preview model before saving it

2009-10-22 Thread Ethan Jucovy
Do you need one-time previews ("are you sure you want to save this?") or
real drafts that can be viewed more than once?  If you just need an
intermediate preview step for the user who's submitting the data, you can do
it without saving any data on the backend --

write a "preview" view that validates the POSTed data without committing
 and then
renders a template with a form that includes that data by default, and which
will POST to the real save view.

I like to put the data in hidden fields, and render a representation of the
previewed data separately.  That way the "save for real" form can just look
like a button to the user, and you can have a separate form for modifying
the data and going through the preview cycle again.

I haven't done anything custom in the django admin, but I assume this
technique can work there too.

Hope this helps,

egj

On Thu, Oct 22, 2009 at 8:12 AM, Aaron  wrote:

>
> I've thought about using a "published" boolean but I'm not sure how
> that would help.
>
> These models are displayed on a live site, and it will be existing
> models I'll be editing and previewing. While a model is in "draft
> mode" I still want the old unchanged version of the model displayed on
> the live site. I'm not sure how I'm going to store either the original
> or the draft versions of the model, or how I'm going to replace the
> original with the draft after I commit its changes.
>
> On Oct 21, 5:38 pm, akonsu  wrote:
> > hello,
> >
> > anything is possible. you just need to decide how you are going to
> > store your changes before the model gets "really" saved so that the
> > preview functionality works. where would preview get the values from?
> > i propose a "published" boolean field in the model.
> >
> > konstantin
> >
> > On Oct 21, 3:41 pm, Aaron  wrote:
> >
> > > I'm wanting to set up model previews in the admin. I've been following
> > > this guide:
> >
> > >http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-pre.
> ..
> >
> > > However, that guide seems to only apply to models that have already
> > > been saved (how is it different from "View on site"?). I wish to be
> > > able to make changes to my model, click on "Preview", and see what my
> > > model page will look like *before* saving it in the admin. Is this
> > > possible?
> >
>

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



Re: Preview model before saving it

2009-10-22 Thread Aaron

I've thought about using a "published" boolean but I'm not sure how
that would help.

These models are displayed on a live site, and it will be existing
models I'll be editing and previewing. While a model is in "draft
mode" I still want the old unchanged version of the model displayed on
the live site. I'm not sure how I'm going to store either the original
or the draft versions of the model, or how I'm going to replace the
original with the draft after I commit its changes.

On Oct 21, 5:38 pm, akonsu  wrote:
> hello,
>
> anything is possible. you just need to decide how you are going to
> store your changes before the model gets "really" saved so that the
> preview functionality works. where would preview get the values from?
> i propose a "published" boolean field in the model.
>
> konstantin
>
> On Oct 21, 3:41 pm, Aaron  wrote:
>
> > I'm wanting to set up model previews in the admin. I've been following
> > this guide:
>
> >http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-pre...
>
> > However, that guide seems to only apply to models that have already
> > been saved (how is it different from "View on site"?). I wish to be
> > able to make changes to my model, click on "Preview", and see what my
> > model page will look like *before* saving it in the admin. Is this
> > possible?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Preview model before saving it

2009-10-21 Thread akonsu

hello,

anything is possible. you just need to decide how you are going to
store your changes before the model gets "really" saved so that the
preview functionality works. where would preview get the values from?
i propose a "published" boolean field in the model.

konstantin

On Oct 21, 3:41 pm, Aaron  wrote:
> I'm wanting to set up model previews in the admin. I've been following
> this guide:
>
> http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-pre...
>
> However, that guide seems to only apply to models that have already
> been saved (how is it different from "View on site"?). I wish to be
> able to make changes to my model, click on "Preview", and see what my
> model page will look like *before* saving it in the admin. Is this
> possible?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Preview model before saving it

2009-10-21 Thread Aaron

I'm wanting to set up model previews in the admin. I've been following
this guide:

http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-previews/

However, that guide seems to only apply to models that have already
been saved (how is it different from "View on site"?). I wish to be
able to make changes to my model, click on "Preview", and see what my
model page will look like *before* saving it in the admin. Is this
possible?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---