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

Тел: +7 965 3737 888

429

Просмотров

0

Ответов

Dynamically change admin widgets at runtime

<h1>django-adminwidgetswap</h1>
<p>adminwidgetswap is used for dynamically swapping out widgets from django's generated admin.
</p>
<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>

<h1>Author</h1>
<p><a href="http://www.davisd.com">David Davis</a>
   (http://www.davisd.com)
   <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>

<h1>Usage</h1>
<p>To change a widget in django's admin, just put adminwidgetswap.py on the python path, import adminwidgetswap.py and use:
</p>
adminwidgetswap.swap_model_field(model, field, widget)
<p>...to change a widget for a direct model admin's field
</p>
<hr>adminwidgetswap.swap_model_inline_field(model, field, widget)
<p>...to change widgets for inlines of a specific model and field
</p>
<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
</p>
<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
</p>

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

Вопрос полезен? Да0/Нет0
file_2689.py(2.0Кб)
None