On Tue, Jul 14, 2009 at 12:15 PM, The Danny Bos <danny...@gmail.com> wrote:

>
> Heya, am trying to simply save 3 values to a database, without using
> Forms.
>
> In the Template:
>
> <form action="rating/" method="post">
>        <input type="hidden" name="record_id" value="1" />
>        <input type="hidden" name="user_id" value="2" />
>        Rate This: <select name="rating">{% for n in numbers %}<option
> value="{{ n }}">{{ n }}</option>{% endfor %}</select>
>        <input type="submit" value="Rate" />
> </form>
>
> In the View:
>
> from mysite.rating.models import Rating
> def critics_rating(request):
>        try:
>                record_id = request.POST['record_id']
>                user_id = request.POST['user_id']
>                rating_val = request.POST['rating']
>
>                rating = Rating()
>                rating.rating = rating_val
>                rating.item = record_id
>                rating.writer = user_id
>                rating.save()
>
>                return HttpResponseRedirect('/')
>        except:
>                pass
>        obj = Record.objects.get(id=record)
>        return render_to_response('record/detail.html', {'object_detail':
> obj}, context_instance=RequestContext(request))
>
> It runs OK (no errors) but doesn't save a single thing, also it goes
> back to the 'detail.html' page fine, but when you hit reload, it sends
> the data again. Again, not saving.
>
> Any ideas what's wrong with this?
> I've done a lot of searching but all people seem to use the Forms
> widget, I was thinking as this is only three fields I'd skip that.
> Silly?


IMHO yes. It will save you a lot of hassles like this and will allow you to
add methods to clean and validate the data when you find that you need it.
The Form class was built to help you at this kind of thing.

To fix this chunk of code, get rid of the try: except statement. There is an
error occurring in you code after the try statement, and you have a catch
all there, so you are bound not to se it happen. That doesn't really help in
debugging,

Hope that helps,

Michael

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