[Django] #19414: Add a "register" class decorator for admin.

17 views
Skip to first unread message

Django

unread,
Dec 3, 2012, 6:53:33 AM12/3/12
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+--------------------
Reporter: stavros | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
The syntax for registering an admin class is a bit unpythonic, so I
propose that the admin.site.register method should also have the
capability of being used as a decorator.

A simple implementation is below:

{{{
def register_admin(model):
def wrapper(klass):
admin.site.register(model, klass)
return klass
return wrapper
}}}

I feel that

{{{
@register(MyModel)
class AdminClass:
pass
}}}

is more pythonic than

{{{
class AdminClass:
pass
register(MyModel, AdminClass)
}}}

which just screams "decorator".

--
Ticket URL: <https://code.djangoproject.com/ticket/19414>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 3, 2012, 9:10:03 AM12/3/12
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------

Reporter: stavros | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by julien):

* needs_better_patch: => 0
* needs_docs: => 0
* component: Uncategorized => contrib.admin
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:1>

Django

unread,
Dec 14, 2012, 8:04:37 PM12/14/12
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold

Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by BHold):

* owner: nobody => BHold


--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:2>

Django

unread,
Dec 17, 2012, 8:07:49 PM12/17/12
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by BHold):

* has_patch: 0 => 1


Comment:

Added pull request: https://github.com/django/django/pull/599

I added a decorator that registers Model/ModelAdmin pairs with AdminSites.
I mostly followed how the AdminSite.register method currently does this.

Passes all tests, including those I added.

This is only my 2nd time contributing to the project, and first time
writing Sphinx docs, so please let me know if I didn't follow any
conventions!

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:3>

Django

unread,
Jan 25, 2013, 10:29:53 AM1/25/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by stavros):

Why not just reuse admin.site.register? It looks like you reimplemented
the method?

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:4>

Django

unread,
Jan 28, 2013, 1:31:58 PM1/28/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by BHold):

Replying to [comment:4 stavros]:


> Why not just reuse admin.site.register? It looks like you reimplemented
the method?

The decorator function should behave a little differently than the normal
register method of the Site. For one, it should accept a 'site' argument
so that a user can use it with a custom Site model. It also should be able
to accept multiple models as arguments that will be all be linked to the
decorated AdminClass in the Site's registry.

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:5>

Django

unread,
Jan 28, 2013, 1:34:06 PM1/28/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by stavros):

Sure, but you don't have to reimplement the whole admin.site.register
method, you can just wrap it and add the extra functionality needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:6>

Django

unread,
Jan 28, 2013, 10:34:53 PM1/28/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by BHold):

Replying to [comment:6 stavros]:


> Sure, but you don't have to reimplement the whole admin.site.register
method, you can just wrap it and add the extra functionality needed.

True, I pushed up a new commit that does just that! What do you think?

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:7>

Django

unread,
Jan 29, 2013, 5:47:11 AM1/29/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by stavros):

Much better! I would not have added the "Unsupported arguments" check if I
wrote it, just because someone might want to construct a dict with extra
stuff and pass it (plus, ignoring kwargs isn't bad for you), but otherwise
it looks great to me.

Can someone official chime in? This looks like a very good pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:8>

Django

unread,
Jan 29, 2013, 10:00:26 AM1/29/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by BHold):

Replying to [comment:8 stavros]:


> Much better! I would not have added the "Unsupported arguments" check if
I wrote it, just because someone might want to construct a dict with extra
stuff and pass it (plus, ignoring kwargs isn't bad for you), but otherwise
it looks great to me.
>

> Can someone official chime in? This pull request looks very good.

Yeah, perhaps that Unsupported Arguments check was unneeded, I removed it.

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:9>

Django

unread,
Jan 31, 2013, 4:39:58 PM1/31/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by rafales):

I think you should also import this decorator in
{{{django/contrib/admin/__init__.py}}}.

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:10>

Django

unread,
Sep 18, 2013, 11:44:48 AM9/18/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: closed
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"98514849dce07acfaa224a90a784bba9d97249e5"]:
{{{
#!CommitTicketReference repository=""
revision="98514849dce07acfaa224a90a784bba9d97249e5"
Fixed #19414 -- Added admin registration decorator

Thanks stavros for the suggestion.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:11>

Django

unread,
Sep 19, 2013, 6:26:03 AM9/19/13
to django-...@googlegroups.com
#19414: Add a "register" class decorator for admin.
-------------------------------+------------------------------------
Reporter: stavros | Owner: BHold
Type: New feature | Status: closed
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"e23de9e350d716c4d9ebe0b27c9f2752fe1aa543"]:
{{{
#!CommitTicketReference repository=""
revision="e23de9e350d716c4d9ebe0b27c9f2752fe1aa543"
Fixed typo in exception message; refs #19414

Thanks Alexey Boriskin for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19414#comment:12>

Reply all
Reply to author
Forward
0 new messages