English 中文(简体)
Django 校对和表决
原标题:Django threadedcomments and voting

在我的项目中,我用django-threadedcomments and django-voting来实现类似红色的评论表决制度。

我 everything弄了一切正确的东西,我能够成功地记录对每一个已读评论和孩子的投票,然而,我对如何整理评论感到困惑,以便使最有分的评论上升到顶头。

是否通过模板标签? 我曾试图这样做,并回到一份清单,这些物品由<条码><>分/条码>订购,但评论的父母与子女之间的关系却被夸大。 我在这里做的是:

class OrderByVotesNode(template.Node):
    def __init__(self, queryset_var, direction="desc"):
        self.queryset_var = template.Variable(queryset_var)
        self.direction = direction

    def render(self, context):
    key = self.queryset_var.var
    value = self.queryset_var.resolve(context)
    try:
        direction = template.Variable(self.direction).resolve(context)
    except template.VariableDoesNotExist:
        direction = "desc"
    model = value.model
    qn = connection.ops.quote_name
    ctype = ContentType.objects.get_for_model(model)
    by_score = model.objects.filter(id__in=[f.id for f in value]).extra(select={"score": """
            SELECT coalesce(SUM(vote), 0 )
            FROM %s
            WHERE content_type_id = %s
            AND object_id = %s.%s
        """ % (qn(Vote._meta.db_table), ctype.id, qn(model._meta.db_table), qn(model._meta.pk.attname))},
        order_by=[(direction == "desc" and "-" or "") + "score"])
    context[key] = by_score
    return u""

任何帮助或建议都将受到高度赞赏。 感谢!

最佳回答

有两个战略:

(1) 你们只想就每一个问题发表最崇高的评论。 对这一意见没有父母意见的问题加上限制(我不肯定如何准确设计校对模式)。

(2) 您取得定购结果,并向其根母提出每一项意见。 然后,你从顶部向下层过滤重复。 这样,每个胎面的分辨率按胎面上任何评论的最高分。 更难以执行,坦率地说,这似乎像我所想的最直观秩序。

在你完成这项工作之后,你定下了一份清单,你在模板中以已准备好的方式表明这些意见(我假定,你将进行一些模版的重新入侵)。

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签