/djangoratings/models.py
Python | 30 lines | 25 code | 5 blank | 0 comment | 0 complexity | e8e84acb9b58bb0276c7cdb4d1fa7eda MD5 | raw file
Possible License(s): BSD-3-Clause
- from django.db import models
- from django.contrib.contenttypes.models import ContentType
- from django.contrib.auth.models import User
- class Vote(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.PositiveIntegerField()
- key = models.CharField(max_length=32)
- score = models.IntegerField()
- user = models.ForeignKey(User, blank=True, null=True)
- ip_address = models.IPAddressField()
- class Meta:
- unique_together = (('content_type', 'object_id', 'key', 'user', 'ip_address'))
- def partial_ip_address(self):
- ip = self.ip_address.split('.')
- ip[-1] = 'xxx'
- return '.'.join(ip)
- partial_ip_address = property(partial_ip_address)
- class Score(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.PositiveIntegerField()
- key = models.CharField(max_length=32)
- score = models.IntegerField()
- votes = models.PositiveIntegerField()
-
- class Meta:
- unique_together = (('content_type', 'object_id', 'key'),)