Django的星级评级系统和AJAX [英] Django star rating system and AJAX

查看:435
本文介绍了Django的星级评级系统和AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个星级系统上的Django的网站。

I am trying to implement a star rating system on a Django site.

存储在我的模型中的评分进行排序,作为正在显示的页面上的得分。但我想用户将能够在不刷新或页面变化率一个页面(从1到5本质上)。

Storing the ratings in my models is sorted, as is displaying the score on the page. But I want the user's to be able to rate a page (from 1 to 5 essentially) without a refresh or change of page.

我发现了以下内容,喜欢这里的明星的风格: HTTP ://jvance.com/blog/2008/09/22/JQueryRaterPluginNew.xhtml

I have found the following, and like the style of the stars here: http://jvance.com/blog/2008/09/22/JQueryRaterPluginNew.xhtml

目前有JavaScript和Ajax的了解有限。有谁知道如何利用明星在上面的例子结合AJAX和Django的,所以你可以不用当用户选择一个评级刷新页面来更新数据库(型号)?

Currently have a limited understanding of javascript and AJAX. Does anyone know how to use the stars in the above example combined with AJAX and Django, so you are able to update the database (models) without a page refresh when a user selects a rating?

有同样重要的是用户只能够投一次,也就是说,它们不能两次评价的页面。它存储在模型中是否已经投票,他们的previous投票结果。但如何将我能够修改的星星,以显示这个?

It is also important that users are only able to vote once, i.e. they are not allowed to rate a page twice. It is stored in the models whether they have already voted and what their previous vote was. But how would I be able to modify the stars to show this?


所以,如果你知道如何做这些事情,或者更恰当星级图形解决方案,或任何好的教程......请大家分享。谢谢你。

So if you know how to do these things, or a more appropriate star rating graphics solution, or any good tutorials... please do share. Thank you.

推荐答案

AJAX听起来很吓人和混乱,但它并没有如此。基本上你想要做的就是发布一些数据到一个特定的URL /视图组合。请参见 jQuery.post 的详细信息,使用AJAX将数据发送到服务器。

AJAX sounds scary and confusing but it doesn't have to be. Essentially what you want to do is post some data to a particular url/view combo. See jQuery.post for more information on using AJAX to send data to the server.

#urls
urlpatterns += patterns('',
url(r'^article/rate/', 'article.rate'),

#views 
def rate(request):
    if request.method == 'POST':
       # use post data to complete the rating..

#javascript
$.post("/article/rate", { rating: 3, article: 2 },
    function(data) {
       // success! so now set the UI star to 3
});

据我所知,星级评级产生的无线电控制和CSS。所以,如果你想显示每个用户的额定电流在页面加载,只是有你的模板呈现与相关的无线电的检查选项。

这篇关于Django的星级评级系统和AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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