lck.django 0.8.5 documentation

This Page

lck.django.score.models

lck.django.score.models

Models holding votes for objects of different types. Usage:

TotalScore.get_value(object) -> int
TotalScore.update(object, voter, value, [reason]) -> int

Classes

class TotalScore(*args, **kwargs)

Bases: django.db.models.base.Model

Holds the integer value of the total score for votes on a specific content_object. The value is updated whenever a Vote object is created, modified or deleted. Don’t alter it directly.

classmethod get_stats_for_model(cases, model, instance=None, ct=None)

Returns a list of stats computed using the specified cases which are a sequence of filtering arguments for the TotalScore vote_set for the specified model (and optionally: instance).

classmethod get_value(object[, voter, ct]) → int

Returns the current score for the specific object or 0 if no-one voted for it yet. Optionally gets value for a specific voter.

classmethod update(object, voter, value[, reason, ct]) → int

Updates the score on object by voting the specific integer value as user voter. Optionally, a reason can be added to the vote. If the voter already voted for this object, she can cancel her vote by specifying value that is the opposite to the one already given. Other attempts to vote multiple times for a single object will be silently ignored.

Conveniently returns the updated total score for the given object.

class Vote(*args, **kwargs)

Bases: lck.django.common.models.TimeTrackable

A single vote. Total score value is updated upon creation and alteration of Vote instances, don’t update it directly.