Hello James, The reason I am following this approach is because this is what was suggested in the documentation, for the scenario where you need to have a form within a DetailsView. Although even when I got my code to be identical to the documentation example, I still dont get an object created. Still, on form submit, the method get_success_url() of PostComment formview is called. I am currently using django 1.7.
On Tuesday, 28 July 2015 11:32:13 UTC+3, James Schneider wrote: > > Is there a specific reason you aren't just using CreateView rather than > trying to mix in a bunch of classes and trying to roll the post() logic > yourself? You can probably cut a very large portion of code out and make > this super simple. > > > https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#model-forms > > You should also consider upgrading Django immediately to a newer version, > as 1.6 is no longer supported. > > -James > The override is this, I was experimenting with save.. > > >> class CommentForm(forms.ModelForm): >> class Meta: >> model = Comment >> exclude = ("parent_post","created_at") >> >> >> def create_view(request, **kwargs): >> print "IN VIEW" >> if request.method == "POST": >> parent_fk = self.object >> print "PARRENT" >> print parent_fk >> form = CommentForm(request.POST) >> if form.is_valid(): >> new_comment = form.save(commit=False) >> new_comment.parent_post = parent_fk >> new_comment.save() >> return HttpResponseRedirect(request.META.get( >> 'HTTP_REFERER')) >> >> >> -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ac05d55-4b68-4afa-a00b-65dfd3a4c939%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

