Anonymous Anonymous - 17 days ago
2818 0

I have a listing page (call it a page to list the draft blogs or unpublished blogs).

When I click a blog item from the draft, it shows the details on read-only format

It provides four functionalities - Close, Edit, Delete, Publish.

I have completed Close by calling {% url 'blog:drafts' %}, Edit by calling a class derived from UpdateView and delete by calling a class derived from DeleteView.

However, I am stuck at publish since there is no view present to create a class based view and get it done.

Other option was to define a function and then invoke that function in urls.py

I run into issues when I try this
I keep receiving error saying that the function that I invoked is not a valid view
I am stuck at this error message for days. Is there any alternate ways to write a "publish" function inside the DetailView class and then invoke that function for the active object from the html template?

Python

-1 down vote favorite I have a listing page (call it a page to list the draft blogs or unpublished blogs). When I click a blog item from the draft, it shows the details on read-only format It provides four functionalities - Close, Edit, Delete, Publish.

my blogpost_detail.html
------------------------------------------------------------------------------------------
{% if post.published_date %}
        <div class="date postdate">
            {{post.published_date}}
        </div>
    {% else %}
        <a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
    {% endif %}

my urls.py
------------------------------------------------------------------------------------------

app_name = 'blog'

urlpatterns = [
    url(r'^$',views.BlogPostListView.as_view(), name='all'),
    url(r'^draft/$',views.DraftBlogListView.as_view(), name='draft'),
    url(r'^create/$',views.CreateBlogPostView.as_view(), name='create'),
    url(r'^detail/(?P<pk>\d+)$',views.BlogPostDetailView.as_view(), name='detail'),    
    url(r"^edit/(?P<pk>\d+)/$", views.BlogPostUpdateView.as_view(), name="edit"),
    url(r'^publish/(?P<pk>\d+)/$',views.blogpost_publish, name='publish'),
    url(r'^remove/(?P<pk>\d+)/$',views.BlogPostDeleteView.as_view(), name='delete'),    
]

my views.py relevant to publish (this view class both class-based views derived from templates and then function based ones, none of the function based views are getting accepted)
------------------------------------------------------------------------------------------
@login_required
def blogpost_publish(request,pk):
    post = get_object_or_404(BlogPost,pk=pk)
    post.publish()
    return render(request,'post_draft_list.html','blog:draft')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download