- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the help center为指导。
9年前关闭。
我想要可重复使用的评级(5 星的典型布局)。
我找到了这个 http://www.thebroth.com/blog/119/css-rating-stars这解释了如何使用 css 显示它。
为了实际收集评级,我正在考虑使用图像 map 或简单的单选按钮。
我想在各种不同的模型上使用它。
你会怎么做?
我应该创建一个小部件还是可以使用模板来完成?
实际上,我很惊讶在网上找不到任何关于此的内容。是这么简单,还是不常见?
最佳答案
如果在 django-users mailing list 上收到一些有趣的答案:
迈克:
Well you can create a widget, I like a seperate rating model myself. That collects the value and then adds that to a total and creates a score or average. The model stores the total votes and the total score, which I divide and get my average, (I do the math in the view). Adding it to other models with a foreign key relation. Enforcing that users vote only once is rarely enforced outside of the current session or cookie lifetime. If you want it persistance, I'm notfgv6gw33TT sure off the top of my head what is best for this, but would require only registered users vote. Now, you just display the rating form, I would do it as a template inclusion tag and put the tag in my templates. This tag has the basic submit form, the form it's self is two fields, with a select box (I went simple this way) and a hidden field labeled next that points back to this page, that I can redirect to. When the user submits, in my views to handle the forms action, I just increment the votes and total score and redirect back to the page the vote was taken on. This is using the traditional submit button, posting the form to a url, returning a full view. If you do something with javascript that illuminates the number of stars for the rating and click on the stars to submit, here you might want to post it as json object using xhr request, update the view and return a json object with the updated rating values, if it's a 200, update the page with the new values after voting (returned with the 200). If it's a 500, deal with the error, letting the user know, there was a problem voting and reset the stars. This is what I do, or would do in your position, if anyone has a better idea, please speak up. Hope this helps. Mike
I actually just did 5-star ratings for a project I'm working on, and have been trying to figure out if I have anything reusable worth releasing as a package (and trying to find the time to figure that out..) I'll outline what I did and what I used to do it. I used django-ratings[1,2] for the backend and hooked up its RatingField to my rateable models. I like jQuery, so for the frontend I used the jquery-star-rating plugin[3,4] as a base. It turns a collection of radio buttons into a star widget. I haven't looked closely at the implementation but I think it's basically using the same CSS technique described in your link. To get started you just need to include its JS and CSS and add class="star" to the radio buttons in your form. I then just wrote some view code that sends the request data from the radio buttons to django-ratings. Super simple stuff, just used the django-ratings RatingManager API and handled the exceptions it throws -- I've pasted the snippet from my code at [5]. (I'm using a somewhat old version of django-ratings b/c I haven't had the time to upgrade; it might look a little different now, I'm not sure.) Finally, I wanted two more things: 1) If a user has already rated an item and views the "rate this item" form again, the "star widget" should be preset with the user's previous rating, instead of just showing five blank stars. I realized the easiest way to do this was from the client side: an onload event that simulates the user clicking on the star he already clicked on. My view and template code for that is at [6]; I just figured out the HTML formats that jquery-star-rating sets and expects, and clicked on the appropriate star for the user's existing rating. 2) When viewing the item, users' ratings should show up as non-interactive stars, instead of as numbers. I wrote a dumb-as-nails template filter designed to take a number (the rating) and return a bunch of star images. Again, I just used the HTML formatting and CSS classes from jquery-star-rating. My code for this is at [7]. I was thinking it'd be neat to put some of this in a django-form Field that renders the radio buttons and triggers jquery-star-rating all in one go, and handles the submission to the django-ratings backend. But I haven't had a chance to figure that out yet. Anyway, hope this helps, Ethan 1 http://github.com/dcramer/django-ratings [2] http://pypi.python.org/pypi/django-ratings [3] http://www.fyneworks.com/jquery/star-rating/ [4] http://code.google.com/p/jquery-star-rating-plugin/ [5] http://pastebin.ca/1650596 [6] http://pastebin.ca/1650609 [7] http://pastebin.ca/1650616
关于django - 最佳实践 : How to best implement Rating-Stars in Django Templates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1649632/
SELECT username, (SUM(rating)/count(*)) as TheAverage, count(*) as TheCount FROM ratings WHERE month
通常我的计数器指标查询如下所示: rate(metric_total[5m]) rate(metric_total[$__interval]) 但是在查看使用 Prometheus 和 Grafana
@Override public void onPositiveButtonClicked(int value, @NotNull String comments) { Rating rati
我尝试创建一个自定义评级栏。我不使用 style 因为我只用过一次。因此,我在 drawable 文件夹中创建了一个 layer-list(它的名称是 custom_rating_bar.xml):
我尝试通过 Django 评级应用程序评级来排序一组模型对象。我在我看来构建了一个 order_by 函数,该函数工作正常,但当我进入评级字段时,我收到此错误:“评级值必须是评级实例,而不是'100”
更新:我输错了 2 个变量...太尴尬了。感谢大家的努力! 抱歉,我发现我为 2 个不同的环境输入了错误的值,第一个我设置了 sort = 0 和 rating=1 但后来在 irb 中我设置了 so
当我使用 Keras 定义模型时,大多数时候都会收到此警告。它似乎以某种方式来自 tensorflow: WARNING:tensorflow:From C:\Users\lenik\AppData\
我有一个二元分类问题,类别背景 (bg) = 0,信号 (sig) = 1,我正在为此训练神经网络。出于监控目的,我尝试在 Keras 中使用 TensorFlow 后端实现自定义指标,该指标执行以下
所以我们有如下电影评分关系数据库: mysql> select * from ratings; +-----+-----+------+ | uid | mid | rid | +-----+-
我正在使用 AVAudioRecorder。我以 44100 采样率以 caf 格式 录制音频。就记录成功了。录制后,我想转换已录制的 caf 采样率为 11025 和 22050 的音频文件。是否可
因此,我们的 ASP.NET4 Web 应用程序中有一个利率计算器类,它使用 Microsoft.VisualBasic.Financial.Rate 来计算名义利率(基于输入参数)。 我们注意到,对
我想用生成器构建一个数独游戏。我已经想出了在没有难度级别的情况下如何做的一切:简单、中等、困难。我的问题是根据难度级别我应该隐藏多少个数字?任何想法。 最佳答案 我很确定数独谜题的难度等级不是根据缺失
如何防止客户对产品进行多次评分?最好使用存储 IP 地址的 cookie,还是最好将用户评级存储在数据库中?我正在使用 MySQL 和 ColdFusion。 干杯! 最佳答案 如果您有用户帐户,请将
项目简介 rate-limit 是一个为 java 设计的渐进式限流工具. 目的是为了深入学习和使用限流,后续将会持续迭代. 特性 渐进式实现 。 支持独立于 spri
我们使用 spring-cloud-gateway 使用 RedisRateLimiter 进行速率限制。如果我们有一个按键来按每条路线进行速率限制,一切都可以立即使用。但是,我们有一个用例,其中针对
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 去年关闭。 Improve th
Lyft文档(https://developer.lyft.com/docs/rate-limits)中有一条信息,即“费率限制是全局的,并基于每个客户端ID强制执行。”。真的是这样吗? Lyft会根
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
引自普罗米修斯 Count and sum of observations文档: To calculate the average request duration during the last 5
引自普罗米修斯 Count and sum of observations文档: To calculate the average request duration during the last 5
我是一名优秀的程序员,十分优秀!