I have this in post_detail.html for Publish button (inside a tags) under else section for those posts without published dates
class="btn btn-secondary" href="{% url 'post_publish' pk=post.pk %}">Publish
In urls.py I have the following:
path('post//publish/', views.post_publish, name='post_publish')
In views.py I have the following:
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return redirect('post_detail', pk=pk)
Expected Behaviour: (1) Redirect to post_detail page and (2) Home page updated with published post
Observed behaviour: (1) Redirect to post_detail BUT publish button still visible and (2) Home page not updated
Went to admin page and checked the post, published date field is still empty -> That is consistent with the observed behaviour.seems to be the reason for observed behaviour
Cannot figure out why the published_date field is not getting updated.
I have this in post_detail.html for Publish button (inside a tags) under else section for those posts without published dates class="btn btn-secondary" href="{% url 'post_publish' pk=post.pk %}">Publish
In urls.py I have the following: path('post//publish/', views.post_publish, name='post_publish')
In views.py I have the following: def post_publish(request, pk): post = get_object_or_404(Post, pk=pk) post.publish() return redirect('post_detail', pk=pk)
Expected Behaviour: (1) Redirect to post_detail page and (2) Home page updated with published post
Observed behaviour: (1) Redirect to post_detail BUT publish button still visible and (2) Home page not updated
Went to admin page and checked the post, published date field is still empty -> That is consistent with the observed behaviour.seems to be the reason for observed behaviour
Cannot figure out why the published_date field is not getting updated.