I need a widget, which should only display a block, because i will add functionality with jQuery. I am trying to include the javascript and stylesheet trough the "Media" class of Widget and it doesn't work for me.
Here is the code:
class StarsWidget(Widget):
"""
Widget with stars for rating
"""
class Media:
js = (
settings.MEDIA_URL + 'js/rating.js',
)
css = {
'screen': (
settings.MEDIA_URL + 'css/rating.css',
)
}
def render(self, name, value, attrs=None):
if value is None: value = ''
attrs = {'id':'ratingX', 'class':'rating'}
final_attrs = self.build_attrs(attrs, name=name)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_unicode(value)
return mark_safe(u'<div %s ></div>' % flatatt(final_attrs))
Any suggestions or help will be appreciated
Are you actually including the form media in your template anywhere?
{% block extrahead %}
{{ form.media }}
{% endblock %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With