class DeletionMixin
from django.views.generic.edit import DeletionMixin
A mixin providing the ability to delete objects
Descendants
Attributes
Defined in | |
---|---|
success_url = None
|
DeletionMixin |
Methods
def
delete(self, request, *args, **kwargs):
DeletionMixin
¶
def
delete(self, request, *args, **kwargs):
DeletionMixin
¶
Calls the delete() method on the fetched object and then redirects to the success URL.
296 297 298 299 300 301 302 303 304 | def delete(self, request, *args, **kwargs):
"""
Calls the delete() method on the fetched object and then
redirects to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
return HttpResponseRedirect(success_url)
|
def
get_success_url(self):
DeletionMixin
¶
def
get_success_url(self):
DeletionMixin
¶
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | def get_success_url(self):
if self.success_url:
# force_text can be removed with deprecation warning
self.success_url = force_text(self.success_url)
if PERCENT_PLACEHOLDER_REGEX.search(self.success_url):
warnings.warn(
"%()s placeholder style in success_url is deprecated. "
"Please replace them by the {} Python format syntax.",
RemovedInDjango110Warning, stacklevel=2
)
return self.success_url % self.object.__dict__
else:
return self.success_url.format(**self.object.__dict__)
else:
raise ImproperlyConfigured(
"No URL to redirect to. Provide a success_url.")
|
def
post(self, request, *args, **kwargs):
DeletionMixin
¶
def
post(self, request, *args, **kwargs):
DeletionMixin
¶
307 308 | def post(self, request, *args, **kwargs):
return self.delete(request, *args, **kwargs)
|