You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to change the redirection url after deleting/editing an object I tried changing this but it did not work for some reason. Is there any other easier way? the problem is that I want to redirect to model.attribute.id. and that can't be handled after deleting a model.
Your code snippet, in your CRUD class should read (note, untested code):
defget_delete_view(self):
delete_view_class=self.get_delete_view_class()
classMyDeleteView(delete_view_class): # add self.mixin if you use it.defget_success_url(self):
pass# see below
Now, with that much shorter snippet. Your issue is missing some information, like what do you mean by "did not work", do you have any errors?
On your example you access self.project.id but from the posted code I do not see when are you setting this parameter.
Regardless, what you want to do is override the get_success_url() (ie, the 'pass' in the snippet above) and return the url to redirect to. Here you are basically on the standard django DeleteView, so you should have access to self.object which contains the object about to be deleted.
Note that get_sucess_url() is called before calling self.object.delete(). So, guessing from your snippet, you want:
defget_delete_view(self):
delete_view_class=self.get_delete_view_class()
classMyDeleteView(delete_view_class): # add self.mixin if you use it.defget_success_url(self):
return"/Project/"+self.object.project.id+"/interfacelist")
On a side note, you should use reverse() instead of hardcoding the url like that.
I wanted to change the redirection url after deleting/editing an object I tried changing this but it did not work for some reason. Is there any other easier way? the problem is that I want to redirect to model.attribute.id. and that can't be handled after deleting a model.
def get_delete_view(self):
ODeleteClass = self.get_delete_view_class()
The text was updated successfully, but these errors were encountered: