I'm having trouble figuring out the best way to use ModelForm in the
following situation. I have these post variables coming into the view
course_id
course_department
course_number
And course_id may or may not be an empty string.
If I do
course_form = CourseForm(request.POST)
Then the problem is that if the course already exists, the
CourseForm's says it's not valid. If I do
course = Course.objects.get(pk=request.POST.get(course_id, '')
course_form = CourseForm(request.POST, instance=course)
The problem is that course_id might be an empty string (a bug which I
can't reproduce and don't understand but does happen and I have to
deal with it)
So if I do
course = Course.objects.get_or_create(department =
request.POST.get('course_department', ''), number =
request.POST.get('course_number', ''))
course_form = CourseForm(request.POST, instance=course)
Then the CourseForm is redundant since I have to do all my own
validation to use course_department and course_number in the first
place.
That puts my brain in a recursive loop and I'm having trouble figuring
out the best thing to do. Any suggestions would help. You can see the
actual codebase here: http://code.google.com/p/cube-bookstore/source/browse/trunk/cube/books/views/metabooks.py#109
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment