On 10/28/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 1) {{form.teacher}} doesn't render the actual teacher assigned to that
> course but just the first in the list of teachers.
>
I'm guessing here since I don't have open any project to test it on,
but I suspect that is because you are initializing your form data with
this:
new_data = dict(code=course.code, name=course.name,
description=course.description, teacher=course.teacher,
assistant=course.assistant)
which makes new_data['teacher'] contain a teacher object when you
actually only need a value. You could change that to:
teacher=str(course.teacher.id)
Another thing, maybe you are doing more things that you didn't
included in the pasted code, but I don't see any need for a custom
manipulator there, and I would suggest you to use the default
generated manipulators.
Your code could be more simpler, like this:
def course_edit(request, course_id):
try:
manipulator = Course.ChangeManipulator(course_id)
except:
raise Http404
course = manipulator.original_object
new_data = {}
errors = {}
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data)
manipulator.save(new_data)
return HttpResponseRedirect("/course_edit/%s" % course_id)
else:
new_data = manipulator.flatten_data()
form = forms.FormWrapper(manipulator, new_data, errors)
return render_to_response("course.html", {'form'=form})
> 2) In the manipulator save() method i have to refer to model fields
> with course.teacher_id. Shouldn't i be able to just do course.teacher
> without instantiating a teacher object?
>
No, course.teacher must be a Teacher object. And since you are using a
custom manipulator, you'll need to fetch that object in the save()
method.
Or, as you already noted, you can use course.teacher_id and assign it
a valid id.
Cheers,
Jorge
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---