0
votes

Can someone help me with Django-ratings app? I'm trying to post a rating but the app doesn't seem to do anything. What part am I missing here? Really hard to find examples out there..

My function looks like this (jquery Raty plugin):

$('.raty').raty({
  click: function(score, evt) {
  var vote_url = "/rate/" + $(this).attr('value') + "/" + score + "/" ;

    $.ajax({
      url: vote_url,
      type: "GET",
      success: function(){
        alert('Vote successful!');
      }
});
   }
});

The GET seems to work but i can see in my admin that no votes/scores are registered.

In my URL:

url(r'rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(), {
    'app_label': 'myapp',
    'model': 'MyModel',
    'field_name': 'rating',
}),

EDIT:

I'm getting a 404 error "Invalid model or app_label". But I'm pretty sure thoose are the correct ones.

1
Could you show AddRatingFromModel? - sneawo
sneawo, It's just a view that is part of the original package. I don't think i should have to change something there. But i guess i could post it if you think it helps? Im trying to follow this: pypi.python.org/pypi/django-ratings - user3199840
What does your ajax response returns? You can see this in Chrome Developer Tools > Network, etc. - Andrey Nelubin
Andrey, oh nice I didn't know about that. It says in status/text: 403 FORBIDDEN. Is that a CSRF related problem? I'm still quite new to all this. Not even sure if "post" is the method type i should use here.. - user3199840

1 Answers

1
votes

This applications does not need the POST request. The easiest way to solve the problem is to set 'GET' method in ajax request

$.ajax({
    ...
    type: 'GET'
    ...

To avoid 404 you need to write model name in lowercase. In django.contrib.contenttypes app_label and model use lowercase.

url(r'rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(), {
...
  'model': 'mymodel',
...
}),