I have a PostForm model form to create posts for my blog app. Now the user has two options after filling the post form he/she can publish it immediately or can put it into the drafts for later publishing. when published the user will be redirected to that post's detail view but when drafted it will redirect to user's draft list view. I don't want to create a detail view for the draft posts.
But I am not able to implement how can I redirect a user to two different views with the two different submit option (Publish and draft) in the form.
create view
model = Post
template_name = 'blog/post_form.html'
form_class = PostForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Create'
return context
def form_valid(self, form):
form.instance.author = self.request.user
form.save()
return super().form_valid(form)
post_form.html
model = Post
template_name = 'blog/post_form.html'
form_class = PostForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Create'
return context
def form_valid(self, form):
form.instance.author = self.request.user
form.save()
return super().form_valid(form)