#27273: Make usage of construct_change_message easier outside of admin
---------------------------------+--------------------------------------
Reporter: Alexey Rogachev | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin, form | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Alexey Rogachev):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> I use [https://github.com/etianen/django-reversion django-reversion]
> library in one of my projects. In admin it uses `ModelAdmin`'s change
> message generated by `construct_change_message` method as revision
> comment. Besides admin I also need to generate same change message on
> object creation / editing on frontend part of a site.
>
> Using `construct_change_message` outside of admin is now possible like
> that:
>
> {{{#!python
> from django.contrib.admin import AdminSite
> from enterprises.admin import EnterpriseAdmin
>
> comment = EnterpriseAdmin(enterprise,
> AdminSite).construct_change_message(request, form, formsets, create)
> }}}
>
> `enterprise` is either created or edited model, `create` - boolean
> variable (`True` when create and `False` otherwise).
>
> I think it's not clean to refer to admin from frontend like that.
>
> As a suggestion, we can move the method outside of a class. It does not
> use `self` also.
>
> Another option is to make this method static, but this will just reduce a
> bit of code, and problem of referring from frontend to admin will still
> present.
New description:
I use [https://github.com/etianen/django-reversion django-reversion]
library in one of my projects. In admin it uses `ModelAdmin`'s change
message generated by `construct_change_message` method as revision
comment. Besides admin I also need to generate same change message on
object creation / editing on frontend part of a site.
Using `construct_change_message` outside of admin is now possible like
that:
{{{#!python
from django.contrib.admin import AdminSite
from enterprises.admin import EnterpriseAdmin
comment = EnterpriseAdmin(enterprise,
AdminSite).construct_change_message(request, form, formsets, create)
}}}
`enterprise` is either created or edited model, `create` - boolean
variable (`True` when create and `False` otherwise).
I think it's not clean to refer to admin from frontend like that.
As a suggestion, we can move the method outside of a class. It does not
use `self` also.
Another option is to make this method static, but this will just reduce a
bit of code, and problem of referring from frontend to admin will still
present.
**P. S.** I understand that this was probably initially designed for admin
only, but still sometimes we need it on frontend, so why not reuse
existing functionality to keep code DRY.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27273#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.afcb722252cefdcc83de953a6a48a4ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.