That did not help.

I think I know what the problem is but I don't know how to solve it:

It seems that when I press the Submit button I jump to another view-function
(that inserts a new course). So, I use the same form i two different places,
both for insert and update. How does django know which view-function it
should "return" to?

/Torbjörn

2010/11/7 cootetom <coote...@gmail.com>

> This is a tough one, everything looks okay. I would try removing the
> categories variable from your model class just to see if that is
> causing problems. By the way, you can get that categories list from an
> instance of the Course class in the following way
> c.coursecategories_set.all() presuming CourseCategory has a foreign
> key back to Course and c = a Course instance.
>
> The other thing to check is the POST. Perhaps if it contains a key
> named "id" it would cause an insert, just a guess though.
>
>
>
> On Nov 7, 7:09 pm, Torbjorn <torbjorn.lundqu...@googlemail.com> wrote:
> > Here is the model:
> >
> > class Course(models.Model):
> >     title = models.CharField(max_length=255)
> >     owner = models.ForeignKey(User)
> >
> >     def __unicode__(self):
> >         return self.title
> >
> >     def _getCategories(self):
> >         cc = CourseCategories.objects.filter(course=self)
> >         return cc
> >
> >     categories = property(_getCategories)
> >
> > and the form:
> >
> > class PartialCourseForm(ModelForm):
> >     class Meta:
> >         model = Course
> >         exclude = ('owner')
> >
> > Thanks
> > /Torbjörn
> >
> > On 7 Nov, 16:34, Marc Aymerich <glicer...@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > On Sun, Nov 7, 2010 at 4:21 PM, Torbjorn
> >
> > > <torbjorn.lundqu...@googlemail.com> wrote:
> > > > Hi, I want to update a record but somehow it becomes an INSERT
> > > > instead. This is my code:
> >
> > > > def editcourse(request, course_id):
> > > >    course= Course.objects.get(id=course_id)
> > > >    if request.method == 'POST':
> > > >        form = PartialCourseForm(request.POST, instance=course)
> > > >        if form.is_valid():
> > > >            form.save()
> > > >            return HttpResponseRedirect("/courses/")
> > > >    else:
> > > >        form = PartialCourseForm(instance=course)
> >
> > > >    return render_to_response("editcourse.html", {'form':form})
> >
> > > > What do I wrong?
> >
> > > Can you paste your course model?
> >
> > > --
> > > Marc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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