#33587: Improve SuccessMessageMixin working with BaseDeleteView
----------------------------------+--------------------------------------
Reporter: Chris Chapman | Owner: Dulalet
Type: Bug | Status: assigned
Component: contrib.messages | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by Carlton Gibson):
Hi Chris.
I'm going to say `wontfix` here initially.
`SuccessMessageMixin` is [essentially unchanged
https://github.com/django/django/blame/9c19aff7c7561e3a82978a272ecdaad40dda5c00/django/contrib/messages/views.py
since it was introduced 9 years ago]. In `get_success_message()` you still
have `self.object` available, with everything but the `pk` (that was
nulled during the `delete()` call):
{{{
>>> from django.contrib.auth.models import Group
>>> g = Group(name="Hello")
>>> g.save()
>>> g
<Group: Hello>
>>> g.id
1
>>> g.delete()
(1, {'auth.Group': 1})
>>> g.id
>>> g.name
'Hello'
}}}
Even the `pk` available from `self.kwargs` in the usual case, so you
already have everything available.
The example you gave — `data = {**cleaned_data, "name":
str(self.object)}` — I guess would be relying on the default `__str__`
implementation using the `pk` but you're already overriding
`get_success_message` so there's no reason not to do something better,
like using a `.name` for the `name` key, or implementing a `__str__` that
doesn't depend in `pk`, or using `self.kwargs` directly if that's what you
really want.
As such, I can't see that it's worth the code change adding other ways to
achieve the same thing.
I hope that makes sense.
Happy to consider if there's a use-case that can't be addressed in this
way.
--
Ticket URL: <https://code.djangoproject.com/ticket/33587#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107017fb20d4941-6776b676-821b-478a-a1a1-227d28274dee-000000%40eu-central-1.amazonses.com.