The API¶
After you’ve got your VotableManager
added to your model you can start
playing around with the API.
-
class
VotableManager
([through=None, verbose_name="Votes", field_name='votes', extra_field=None])¶ Parameters: - verbose_name – The verbose_name for this field.
- through – The through model
- field_name – The field name added to the query
- extra_field – The field on your model. It will be updated when up or down
-
up
(user)¶ This adds a vote to an object by the
user
.IntegrityError
will be raised if the user has voted before:>>> comments.votes.up(user)
-
down
(user)¶ Removes the vote from an object. No exception is raised if the user doesn’t have voted the object.
-
exists
(user)¶ Check if user has voted the instance before.
-
all
(user)¶ Get all instances voted by the specify user.
-
count
()¶ The count of all votes for an object.
-
annotate
(queryset=None, user=None)¶ Add annotation data to the
queyset