如何在bootstrap-rating-input中使用Django-ratings [英] How to use Django-ratings with bootstrap-rating-input

查看:128
本文介绍了如何在bootstrap-rating-input中使用Django-ratings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里还有另一个星级评定问题.我想使用 bootstrap-rating-input 输入评分值(1到5),然后已 django-ratings 将评级保存到数据库中.尽管我对javascript有点陌生,但我确实希望用户能够使用星级而不是数字输入形式来投票.您能告诉我如何连接这两个应用程序,以使它们彼此之间玩得开心吗?

Here goes another star rating question. I want to use bootstrap-rating-input to input rating value (1 to 5) and have django-ratings save the rating to the database. Although I'm a little green with javascript, I really want users to be able to vote using star rating instead of a number input form. Could you show me how to hook up these two apps to make them play nice with each other?

  1. 视图和模板是什么样的?
  2. 该如何配置javascript以使整个程序正常工作?

谢谢!

推荐答案

将此添加到您的头部进行测试:
<script src="https://raw.githubusercontent.com/javiertoledo/bootstrap-rating-input/master/src/bootstrap-rating-input.js"></script>

Add this in your head part for test:
<script src="https://raw.githubusercontent.com/javiertoledo/bootstrap-rating-input/master/src/bootstrap-rating-input.js"></script>

现在将此代码添加到您要给予评分的位置

now add this code where you want to give a rating

<input class="my_class rating" data-clearable="" data-max="5" data-min="1" id="some_id" name="your_awesome_parameter" value="" type="number" onchange="console.log($('input.my_class').rating().val())"/>

<input class="my_class rating" data-clearable="" data-max="5" data-min="1" id="some_id" name="your_awesome_parameter" value="" type="number" onchange="console.log($('input.my_class').rating().val())"/>

,简单地,您得到的不是.现在,在控制台中进行评级的Ajax调用并将其添加到您的数据库中.

and simply you get the no. of rating in console now make a ajax call and add it to your DB .

注意:如果您为用户视图尝试使用静态评级,请使用类似的代码
max.times do |i|
%i{class: "glyphicon glyphicon-star#{'-empty' if i>val}"}

Note: In case when you try static ratings for user view use code like that
max.times do |i|
%i{class: "glyphicon glyphicon-star#{'-empty' if i>val}"}

成功后请记住下载 bootstrap-rating-input.js 文件

remember download bootstrap-rating-input.js file after success

这篇关于如何在bootstrap-rating-input中使用Django-ratings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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