Django-Filer FilerImageField how to use widget outside admin

做~自己de王妃 提交于 2019-12-12 02:25:13

问题


I want to use the FilerImageFieldin one of my model field and want the user to edit outside the admin area but when I try to load it, the widget doesn't work correctly and in the browser console I get and error in the javascript generated:

Uncaught TypeError: Cannot read property 'jQuery' of undefined

In here:

            <script type="text/javascript" id="id_featured_image_javascript">
                django.jQuery(document).ready(function(){
                    var plus = django.jQuery('#add_id_featured_image');
                    if (plus.length){
                        plus.remove();
                    }
                    // Delete this javascript once loaded to avoid the "add new" link duplicates it
                    django.jQuery('#id_featured_image_javascript').remove();
                });
            </script>

The field in my model is defined like this:

article_image = FilerImageField(db_column="ARTICLE_IMAGE",
                                 verbose_name=_('Article Image'),
                                 related_name='IPP_ARTICLE_IMAGE')

The field appears like this:

Do you have any idea why I can't use this field widget outside the admin? Do I need to set some configuration for this?

Thank you :)


回答1:


First of all, add {{ form.media }} in your html file, just after the tag <form> and {% csrf_token %}. Then extend the media class in your ModelForm of forms.py as explained by SteinRobert on Github issue: https://github.com/divio/django-cms/issues/6028. It works perfect! Thanks Stein!



来源:https://stackoverflow.com/questions/38512225/django-filer-filerimagefield-how-to-use-widget-outside-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!