Skip to content

Latest commit

 

History

History
59 lines (35 loc) · 1.83 KB

api.rst

File metadata and controls

59 lines (35 loc) · 1.83 KB

The API

After you've got your VoteModel added to your model you can start playing around with the API.

param verbose_name

The verbose_name for this field.

param through

The through model

param field_name

The field name added to the query

param extra_field

The field on your model. It will be updated when up or down

up(user_id)

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_id)

Removes the vote from an object. No exception is raised if the user doesn't have voted the object.

delete(user_id)

Removes the vote from an object. No exception is raised if the user doesn't have voted the object.

exists(user_id, action=UP)

Check if user has voted the instance before.

all(user_id, action=UP)

Get all instances voted by the specify user.

user_ids(action=UP)

Get all user_ids voted the instance

count(action=UP)

The count of all votes for an object.

get(user_id)

Get the whole Vote object for the user. Returns None if no vote present.

annotate(queryset=None, user_id=None, reverse=True, sort=True)

Add annotation data to the queyset

Aggregation

Django does not support aggregation with GenericRelation currently but you still can use annotate:

>>> Comment.objects.filter(article__id=article_id).annotate(num_votes=Count('votes__user'))