django-voting

Django,Jquery,Ajax; refreshing div for voting system not working?

a 夏天 提交于 2019-12-12 07:04:11
问题 I have a working django voting system using up and down keypresses on entries in a database. I need to have the {{ entry.score }} refresh on the page without a reload, as there will be other entries on the page. The {{ entry.text }} can refresh but needs to stay as the same entry until a different keypress selects a different entry. I'm trying to do it with ajax, but get a 500 Internal Server Error and no refresh, GET http://127.0.0.1:8000/voteup/?voteid=30 500 (INTERNAL SERVER ERROR) jquery

Cookies not working with an AJAX call from jQuery to Django

半城伤御伤魂 提交于 2019-12-11 15:36:45
问题 I have a Django site using a 5-star rating system for voting (I use django-ratings) and I would like to store the votings of the users with AJAX calls. On the client side I have a JavaScript function sending a GET request to a URL: $.ajax({ url: url, success: function(data) { alert('Load was performed.'); } }); On the server side I have code setting the cookie: def vote(request, slug, rating): # Some irrelevant code... response = HttpResponse('Vote changed.') response.set_cookie('vote',

How do you join two tables using Django without using raw sql?

荒凉一梦 提交于 2019-12-10 15:14:09
问题 Is is possible to programatically join two tables using Django's ORM? I have two models: Topics and Votes. On my template I have a list of topics that users can up/down vote like Reddit. Everything works as it should except for sorting the results. I cannot figure out how to sort an objects list based off the score which is a sum of each object's vote count. I can retrieve the desired data from postgres without any issue: select i.id, i.title, i.date_created, s.object_id, s.vote, Sum(vote)

How to add attribute '_meta' to an object?

99封情书 提交于 2019-12-02 02:22:01
问题 I'm trying to add the django-voting app to my project. I don't know how to use it in my templates, so I'm adding a new template tags for voting up or down when an user click in buttons. I don't know if there's a well form to do it. My problem is with these kind of line in the template tag: obj = Place.objects.filter(id=object_id) Vote.objects.record_vote(obj, self.user, +1) django print: Caught AttributeError while rendering: 'Place' object has no attribute '_meta' How I can add the attribute