Agreed, I should get used to using Forms. So I gave it a go, the new problem I have is out of my three fields, two need to be hidden and have values automatically assigned from the page they're on. This is freaking me out.
Now I have: # forms.py class RatingForm(forms.Form): record = forms.CharField(widget=forms.HiddenInput) critic = forms.CharField(widget=forms.HiddenInput) rating = forms.ChoiceField(choices=RATING_CHOICES) #views.py def record_detail(request): if request.method == 'POST': form = RatingForm(request.POST) if form.is_valid(): record_rating = Rating() record_rating.rating = form.cleaned_data['rating'] record_rating.record = ???? record_rating.writer = ???? record_rating.save() return HttpResponseRedirect('/') else: ... How do I get the User.ID (as you'll need to be logged in), into that hidden field or the DB. And also the Record.ID from the page I was just on. Know what I mean. Am I way off? I'm new to this, so any detailed help is very welcome. Thanks again, d On Jul 15, 2:37 am, Lakshman Prasad <scorpion...@gmail.com> wrote: > > It runs OK (no errors) but doesn't save a single thing > > It has to run without errors because you have enclosed the whole thing > in try. > > You have to coerce the record_id and user_id into int before assigning > to the model fields, for it to save. > > On Tue, Jul 14, 2009 at 9:45 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? > > -- > Regards, > Lakshman > becomingguru.com > lakshmanprasad.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---