Hello, i realise this is a very old post, but i am trying to implement your 
code here, but it seems some code are missing, i was able to get a form, 
but the contents of my detailView isn't showing, what code am i suppose to 
put here " A view for displaying a single post ". your help will be greatly 
appreciated.
Thank you.
On Tuesday, 28 July 2015 at 12:08:23 UTC+1 latu...@gmail.com wrote:

> Hello James,
>
> Following your advice I turned to using CreateView, and now all the 
> functionality I wanted seems to work fully. As you suggested there is no 
> need for a form.py using this method. When I got more time I might 
> investigate further how to make the original approach work for future 
> reference.  This is the view code:
>
> class PostDetailView(BlogMixin,CreateView):
>
>     """ A view for displaying a single post """
>     template_name = 'post.html'
>
>     model = Comment
>     fields = ['body','author_name'] 
>     def get_context_data(self, **kwargs):
>         context = super(PostDetailView, self).get_context_data(**kwargs)
>         context['post'] =  Post.objects.get(pk=self.kwargs['pk'])
>         return context
>     
>     def form_valid(self, form):
>         obj = form.save(commit=False)
>         obj.parent_post = Post.objects.get(pk=self.kwargs['pk'])
>         obj.save()
>
>        return redirect('post-detail', self.kwargs['pk'])
>
>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29f08e84-de56-4e59-b388-fa895e9f868en%40googlegroups.com.

Reply via email to