开发者

Ideas to implement "vote" ContentType-based app

I want to create an app to allow the voting of any model (thumbs up and thumbs down, pretty much like SO in it's questions and answers), using ContentTypes (like the comments framework or the tags examples in docs).开发者_开发技巧

I just set up the models and templatetags, it's possible to get the count of votes and etc. What bugs me is what should be the best way to make voting possible.

This is the vote class:

class Vote(models.Model):
    TYPES_VOTE = (
        ( 'POS', 'Positive' ),
        ( 'NEG', 'Negative' ),
    )

    type            = models.CharField(max_length=3, choices=TYPES_VOTE, default=None)
    content_type    = models.ForeignKey(ContentType)
    object_id       = models.PositiveIntegerField(db_index=True)

I wrote a simple view that receives the content-type, object id and type of vote (up or down). But I don't know the best way to call this view. Some possibilities:

  • Vote by just GET request, urls.py will catch the request and pass the right content-type(example: url(r'^question/(?P<question_id>)/vote/(?P<vote_type>)/$', voting_views.vote, {'content_type' : ContentType.objects.get_for_model(Question()) }, name='vote_question'),)

  • Vote by POST request, creating a form for the vote that has the ContentType for the object and type of vote. I'm not sure how do implement this, without having two forms for each model in the template that can be voted.

Any ideas?


You can check http://code.google.com/p/django-voting/

It's pretty similar to what you try to do: http://code.google.com/p/django-voting/source/browse/trunk/voting/models.py

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜