- 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/
我经常在 C 标准文档中看到“实现定义”的说法,并且非常将其作为答案。 然后我在 C99 标准中搜索它,并且: ISO/IEC 9899/1999 (C99) 中第 §3.12 条规定: 3.12 I
“依赖于实现”中的“实现”是什么意思? “依赖于实现”和“依赖于机器”之间有什么区别? 我使用C,所以你可以用C解释它。 最佳答案 当 C 标准讨论实现时,它指的是 C 语言的实现。因此,C 的实现就
我刚刚在 Android-studio 中导入了我的项目,并试图在其中创建一个新的 Activity。但我无法在 android-studio 中创建 Activity 。我指的是here我看不到将目
我想知道您对为什么会发生此错误的意见。在陆上生产环境中,我们使用 CDH4。在我们的本地测试环境中,我们只使用 Apache Hadoop v2.2.0。当我运行在 CDH4 上编译的同一个 jar
我正在尝试集成第三方 SDK (DeepAR)。但是当我构建它时,它会显示一个错误。我试图修复它。如果我创建一个简单的新项目,它就可以正常工作。但是我现有的应用程序我使用相机和 ndk。请帮我找出错误
我很好奇为什么我们有 @Overrides 注释,但接口(interface)没有类似的习惯用法(例如 @Implements 或 @Implementation)。这似乎是一个有用的功能,因为您可能
我对 DAODatabase(适用于 Oracle 11 xe)的 CRUD 方法的实现感到困惑。问题是,在通常存储到 Map 集合的情况下,“U”方法(更新)会插入新元素或更新它(像 ID:Abst
Java-API 告诉我特定类实现了哪些接口(interface)。但有两种不同类型的信息,我不太确定这意味着什么。例如,对于“TreeSet”类:https://docs.oracle.com/en
我有一个接口(interface) MLService,它具有与机器学习算法的训练和交叉验证相关的基本方法,我必须添加两个接口(interface)分类和预测,它们将实现 MLService 并包含根
我一直想知道如何最好地为所有实现相同接口(interface)的类系列实现 equals()(并且客户端应该只使用所述接口(interface)并且永远不知道实现类)。 我还没有编写自己的具体示例,但
我有一个接口(interface)及其 2 个或更多实现, public interface IProcessor { default void method1() { //logic
我有同一个应用程序的免费版和高级版(几乎相同的代码,相同的类,到处都是“if”, list 中的不同包, list 中的进程名称相同)。主要 Activity 使用 IMPLICIT Intent 调
这是我为我的应用程序中的错误部分编写的代码 - (id)initWithData:(NSData *)data <-------- options:(NSUInteger)opti
请查找随附的代码片段。我正在使用此代码将文件从 hdfs 下载到我的本地文件系统 - Configuration conf = new Configuration(); FileSys
我想在 MongoDB 中使用 Grails2.5 中的“ElasticSearch”插件。我的“BuildConfig.groovy”文件是: grails.servlet.version = "3
我收到一条错误消息: fatal error: init(coder:) has not been implemented 对于我的自定义 UITableViewCell。该单元格未注册,在 Stor
得到这个错误 kotlin.NotImplementedError: An operation is not implemented: not implemented 我正在实现一个 ImageBut
typedef int Element; typedef struct { Element *stack; int max_size; int top; } Stack; //
Playground 代码 here 例子: interface IFoo { bar: number; foo?: () => void; } abstract class Abst
我想知道如何抑制警告: Category is implementing a method which will also be implemented by its primary class. 我
我是一名优秀的程序员,十分优秀!