DjangoGirls / tutorial-extensions

Additional tasks for tutorial
https://tutorial-extensions.djangogirls.org
Other
162 stars 202 forks source link

Publish button not working as expected #166

Closed pratique21 closed 10 months ago

pratique21 commented 10 months ago

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.

pratique21 commented 10 months ago

Error was in my publish function, missing ( ) on save method. It works now.