Reputation: 3709
I want to reuse any existing voting app in Django.
I tried using Django Voting app - http://code.google.com/p/django-voting/wiki/RedditStyleVoting. This app has following code in models.py
from django.conf.urls.defaults import *
from django.views.generic.list_detail import object_list
from devdocs.apps.kb.models import Link
from voting.views import vote_on_object
But I don't see any 'devdocs.apps.kb.models' in the app. What should I do ? Should I create my own Link class in the models.py ?
Upvotes: 1
Views: 509
Reputation: 966
You should replace "Link" with a model you've created that represents what users are voting on.
Example from the sample project's wiki:
urlpatterns = patterns('',
# Generic view to list Link objects
(r'^links/?$', object_list, dict(queryset=Link.objects.all(),
template_object_name='link', template_name='kb/link_list.html',
paginate_by=15, allow_empty=True)),
# Generic view to vote on Link objects
(r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
vote_on_object, dict(model=Link, template_object_name='link',
template_name='kb/link_confirm_vote.html',
allow_xmlhttprequest=True)),
)
The above url config is essentially creating the url end point for you to like, dislike, or remove your vote for an abstract object, which in the example is a "Link".
You could imagine if you were building a Reddit-like website, users would be posting links. Possible fields on this Link model would be a foreign key to User, a title, and a link.
If this application was similar to StackOverflow, you could potentially make a "Question" and "Answer" model that could then be voted on.
You will also have to create the templates to show your list of Links and when a user likes/dislikes/clears their vote. Likewise this is also detailed in the wiki of the google code project: Reddit Style Voting
Upvotes: 2