Question

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.

Était-ce utile?

La solution

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',
...
}),
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top