Django-filer FilerImageField how to use widget outside admin

220 views
Skip to first unread message

Patricia Santos

unread,
Jul 22, 2016, 7:15:52 AM7/22/16
to Django users

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:


featured_image = FilerImageField(db_column="FEATURED_IMAGE",
                                 verbose_name=_('Featured Image'),
                                 related_name='IPP_ARTICLE_FEATURED_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?


Thank you :)

webmam...@gmail.com

unread,
Jul 23, 2016, 2:04:40 PM7/23/16
to Django users

You can try to create ModelForm:

class YouModelForm(ModelForm)
   
class Meta:
         model
= YouModel
         fields
= ['featured_image', 'other_fields']

in views.py:

def youfunc(request)
   
Youform = YouModelForm()

in template.html:

..................................................... You tags ...................
.....................................................
            {{ Youform.media }}
            {{ Youform.featured_image  }}

This is not full solving. Tell me do You use Modelform for You Model?
Reply all
Reply to author
Forward
0 new messages