django - DeleteView with a dynamic success_url dependent on id -



django - DeleteView with a dynamic success_url dependent on id -

i have app posts, url each post:

url(r'^post/(?p<id>\w+)/$', 'single_post', name='single_post'),

on each post, have comments. able delete each comment post page , homecoming post on.

i have next url deleting comments:

url(r'^comment/(?p<pk>\d+)/delete/$', commentdelete.as_view(), name='comment_delete'),

and know previous research need override get_success_url, i'm not sure how reference post id on. think need utilize kwargs, not sure how. have currently, doesn't work...

class commentdelete(permissionmixin, deleteview): model = comment def get_success_url(self): homecoming reverse_lazy( 'single_post', kwargs = {'post.id': self.kwargs.get('post.id', none)},)

ideas appreciated!

this should work:

def get_success_url(self): # assuming there foreignkey comment post in model post = self.object.post homecoming reverse_lazy( 'single_post', kwargs={'post.id': post.id})

django's deleteview inherits singleobjectmixin, contains get_object method.

django

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -