So, I'm guessing this is impossible.
Any ideas would be great ...

d



On Jul 16, 11:52 am, The Danny Bos <danny...@gmail.com> wrote:
> Hopefully my last question on this,
> How do I get back to the page with the form, perhaps with a "Thank
> You" message, without having the POST still available if you hit
> refresh.
> I figured I'd use 'reverse' but not quite sure why it isn't
> working ...
>
> Here's where I am now:
>
> #views.py
> def record_detail(request, slug):
>         record = Record.objects.get(slug=slug)
>         if request.method == 'POST':
>                 form = RatingForm(request.POST)
>                 if form.is_valid():
>                         record_rating = Rating()
>                         record_rating.item_id = record.id
>                         record_rating.writer_id = request.user.id
>                         record_rating.rating = form.cleaned_data['rating']
>                         record_rating.save()
>
>                         return render_to_response(reverse('record_detail', 
> args=[slug]))
>         else:
>                 form = RatingForm()
>         return render_to_response('records/detail.html', {'record_detail':
> record, 'form': form}, context_instance=RequestContext(request))
>
> I get the below error.
>
> NoReverseMatch at /records/temp-record-name/
> Reverse for 'record_detail' with arguments '(u'temp-record-name',)'
> and keyword arguments '{}' not found.
>
> And even if it does get passed back to the original page, how would I
> have a "Thank You" message?
>
> Thanks again,
>
> d
>
> On Jul 16, 10:49 am, Russell Keith-Magee <freakboy3...@gmail.com>
> wrote:
>
>
>
> > On Thu, Jul 16, 2009 at 8:36 AM, The Danny Bos<danny...@gmail.com> wrote:
>
> > > Any ideas on this one guys?
>
> > > I gave up on it last night.
> > > I feel way off ...
>
> > Ok - some back tracking.
>
> > Your first approach (no forms) should have worked. The reason you
> > didn't get any errors is that your code is explicitly ignoring _all
> > errors_. You are catching all exceptions, passing, and moving on. That
> > means that if an error - ANY minor error - is thrown in your 'form
> > processing' code, then it will be silently ignored.
>
> > Step 1 - Make it be not silent. Instead of using:
>
> > except:
> >     pass
>
> > try using
>
> > except Exception, e:
> >     print 'ERROR!!', e
>
> > And see what it says. You will probably find that it's something
> > really simple, like a typo in a variable name somewhere. Fix those
> > issues, and you should find things start to work- the general approach
> > you describe should be fine.
>
> > Your second attempt, using forms, can be made to work in a number of ways.
>
> > 1) Save the values back from the form.
>
> > record_rating.rating = form.cleaned_data['rating']
> > record_rating.record_id = form.cleaned_data['record']
> > record_rating.writer_id = form.cleaned_data['writer']
>
> > I would also note that your form probably won't have values for record
> > and writer - because they are hidden inputs and you're not providing
> > initial values. Look into the `initial` argument to fields, or to the
> > form as a whole.
>
> > 2) Don't put the values on the form in the first place. After all -
> > they're hidden inputs.
>
> > class RatingForm(forms.Form):
> >        rating = forms.ChoiceField(choices=RATING_CHOICES)
> > ...
> > record_rating.rating = form.cleaned_data['rating']
> > record_rating.record = Record.objects.get(....)
> > record_rating.writer = Writer.objects.get(....)
>
> > 3) Look at using a ModelForm. This will handle the saving of the
> > entire Rating object; however, given that you seem to want to use
> > hidden inputs, you will need to jump through some extra hoops to
> > override the default widgets. Overriding widgets is covered in the
> > docs.
>
> > Yours,
> > Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
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