Russ, this makes a lot of sense, thanks so much.
I'll give it a go now ...


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