I'm trying to add the django-voting app to my project. I do开发者_如何学运维n'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 _meta my object 'Place'?
The problem is that obj
here is not actually an object, but a queryset with one element. You should use get
instead of filter
, as get
actually returns a model instance.
obj = Place.objects.get(id=object_id)
精彩评论