Django-Filer FilerImageField如何在管理员外部使用小部件 [英] Django-Filer FilerImageField how to use widget outside admin

查看:249
本文介绍了Django-Filer FilerImageField如何在管理员外部使用小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模型字段之一中使用FilerImageField,并希望用户在管理区域之外进行编辑,但是当我尝试加载它时,小部件无法正常工作,并且在浏览器控制台中我得到了生成的javascript错误:

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

在这里:

            <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')

该字段显示如下:

您知道为什么我不能在管理员外部使用此字段窗口小部件吗?我需要为此设置一些配置吗?

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?

谢谢:)

推荐答案

首先,在<form>{% csrf_token %}标记之后,在html文件中添加{{ form.media }}.然后按照SteinRobert在Github问题上的解释,在您的ModelForm form.py中扩展媒体类:

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!

这篇关于Django-Filer FilerImageField如何在管理员外部使用小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆