Opened 13 years ago
Closed 11 years ago
#17556 closed New feature (duplicate)
Let Media classes to inherit
Reported by: | Aleksander Zdyb | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | forms media |
Cc: | d1fffuz0r@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Media classes in ModelAdmin
or Form
cannot inherit from other classes:
class BaseMedia: css = {"all": ["base.css", ] } class ExampleAdmin(ModelAdmin): class Media(BaseMedia): js = ["example.js, ]
In the example above, only js media will be available. This is because of the following code in django/forms/widgets.py:
class Media(StrAndUnicode): def __init__(self, media=None, **kwargs): if media: media_attrs = media.__dict__ else: media_attrs = kwargs
__dict__
doesn't include inherited properties.
My proposal is to use getmembers
from inspect
module:
media_attrs = dict(getmembers(media))
I've attached a 2-lines patch. All unit tests passed against revision 17377.
Attachments (2)
Change History (6)
by , 13 years ago
Attachment: | media_inherit.diff added |
---|
comment:1 by , 13 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 12 years ago
Attachment: | media_inherit.2.patch added |
---|
comment:4 by , 11 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The patch needs tests.