0

I tried using the example that they gave on the documentation of this app.

Their example: And adding votes is also simple: Ubicacion.rating.add(score=1, user=request.user, ip_address=request.META['REMOTE_ADDR'])

but it returns me this error:

 'RatingField' object has no attribute 'add'

And I did look up in the fields.py of the app, and indeed there is a function "add"

So I don't know why when I create the object of that class doesn't recognize the attributes of that class?

This is my model:

class Ubicacion(models.Model):
route = models.LineStringField()
coordsdet = models.LineStringField()
fecha = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
objects = models.GeoManager()
rating = RatingField(range=5)

1 Answers1

1

Not familiar with django-ratings, but it looks like you should be calling the rating.add on an instance of your Ubicacion class- not on the class itself.

First create an instance:

myinstance = Ubicacion.objects.create(...)

Then, according to the django-ratings docs you could call add:

myinstance.rating.add(score=1, user=request.user, ip_address=request.META['REMOTE_ADDR'])
dgel
  • 16,352
  • 8
  • 58
  • 75