/usr/share/pyshared/voting/models.py is in python-django-voting 0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | from datetime import datetime
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.db import models
try:
from django.utils.timezone import now
except ImportError:
now = datetime.now
from voting.managers import VoteManager
SCORES = (
(+1, u'+1'),
(-1, u'-1'),
)
class Vote(models.Model):
"""
A vote on an object by a User.
"""
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
object = generic.GenericForeignKey('content_type', 'object_id')
vote = models.SmallIntegerField(choices=SCORES)
time_stamp = models.DateTimeField(editable=False, default=now)
objects = VoteManager()
class Meta:
db_table = 'votes'
# One vote per user per object
unique_together = (('user', 'content_type', 'object_id'),)
def __unicode__(self):
return u'%s: %s on %s' % (self.user, self.vote, self.object)
def is_upvote(self):
return self.vote == 1
def is_downvote(self):
return self.vote == -1
|