1๐
โ
I would not try to mix logic for both usecase in a single view.
class BlogFullPostView(DetailView):
model = Post
template_name = 'full_post.html'
pk_url_kwarg = 'post_id'
context_object_name = 'post'
def get_context_data(self, **kwargs):
context = super(BlogFullPostView, self).get_context_data(**kwargs)
context['comments'] = Comment.objects.filter(post=self.object)
context['form'] = AddCommentForm(initial={'post': self.object })
return context
class CommentFormView(FormView):
form_class = AddCommentForm
def get_success_url(self):
# logic here for post url
# full_post.html
<form method="post" action="{% url "comment_form_view_url" %}">
{{ form }}
</form>
๐คmishbah
Source:stackexchange.com