PageRenderTime 60ms CodeModel.GetById 52ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/djangoratings/models.py

http://django-ratings.googlecode.com/
Python | 30 lines | 25 code | 5 blank | 0 comment | 0 complexity | e8e84acb9b58bb0276c7cdb4d1fa7eda MD5 | raw file
 1from django.db import models
 2from django.contrib.contenttypes.models import ContentType
 3from django.contrib.auth.models import User
 4
 5class Vote(models.Model):
 6    content_type    = models.ForeignKey(ContentType)
 7    object_id       = models.PositiveIntegerField()
 8    key             = models.CharField(max_length=32)
 9    score           = models.IntegerField()
10    user            = models.ForeignKey(User, blank=True, null=True)
11    ip_address      = models.IPAddressField()
12
13    class Meta:
14        unique_together = (('content_type', 'object_id', 'key', 'user', 'ip_address'))
15
16    def partial_ip_address(self):
17        ip = self.ip_address.split('.')
18        ip[-1] = 'xxx'
19        return '.'.join(ip)
20    partial_ip_address = property(partial_ip_address)
21
22class Score(models.Model):
23    content_type    = models.ForeignKey(ContentType)
24    object_id       = models.PositiveIntegerField()
25    key             = models.CharField(max_length=32)
26    score           = models.IntegerField()
27    votes           = models.PositiveIntegerField()
28    
29    class Meta:
30        unique_together = (('content_type', 'object_id', 'key'),)