Задать вопрос

Тел: +7 965 3737 888





Dynamically change admin widgets at runtime

<p>adminwidgetswap is used for dynamically swapping out widgets from django's generated admin.
<p>This allows applications to be packaged generically without the need for WYSIWYG dependencies editors- giving the application consumer the freedom to chose admin widgets without modifying original app source.

<p><a href="http://www.davisd.com">David Davis</a>
   <a href="http://www.davisd.com/blog/2010/04/17/dynamically-change-django-admin-widgets-at-runtime/">dynamically change django admin widets at runtime (django-adminwidgetswap) blog post</a>

<p>To change a widget in django's admin, just put adminwidgetswap.py on the python path, import adminwidgetswap.py and use:
adminwidgetswap.swap_model_field(model, field, widget)
<p>...to change a widget for a direct model admin's field
<hr>adminwidgetswap.swap_model_inline_field(model, field, widget)
<p>...to change widgets for inlines of a specific model and field
<hr>adminwidgetswap.swap_model_and_inline_fields(model, field, widget)
<p>...to change both the widget for the direct model admin's field as well as all inline usages for the model and field
<hr><p>I usually have a project-level application called website, and I put this initialization code inside the website app's <strong>init</strong>.py

<h1>Usage - parameters</h1>
<p>model is the Model class
   (eg. models.GalleryImage)
<p>field is the field name you're looking to swap
   (eg. 'image')
<p>widget is the widget you're going to swap for
   (eg. widgetlibrary.ThumbnailWidget())

Вопрос полезен? Да0/Нет0