Overriding the admin Media class

Posted by shacker on Stack Overflow See other posts from Stack Overflow or by shacker
Published on 2010-03-23T22:28:14Z Indexed on 2010/03/23 22:43 UTC
Read the original article Hit count: 265

Filed under:

Given an admin media class that sets up a rich text editor, like:

class TutorialAdmin(admin.ModelAdmin):

    fields...

    class Media:
        js = ['/paths/to/tinymce.js',]

I would like the ability to selectively override js depending on a field value in the model it references. I've added a "use_editor" boolean to the Tutorial model. The question is, how can I detect whether the current instance has that bool set? I'd like to end up with something like:

class Media:
    if self.use_editor:
        js = ['/path/to/tinymce.js',]
    else:
        js = ''

Ideas? Thanks.

© Stack Overflow or respective owner

Related posts about django