PageRenderTime 10ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. from django.db import models
  2. from django.contrib.contenttypes.models import ContentType
  3. from django.contrib.auth.models import User
  4. class Vote(models.Model):
  5. content_type = models.ForeignKey(ContentType)
  6. object_id = models.PositiveIntegerField()
  7. key = models.CharField(max_length=32)
  8. score = models.IntegerField()
  9. user = models.ForeignKey(User, blank=True, null=True)
  10. ip_address = models.IPAddressField()
  11. class Meta:
  12. unique_together = (('content_type', 'object_id', 'key', 'user', 'ip_address'))
  13. def partial_ip_address(self):
  14. ip = self.ip_address.split('.')
  15. ip[-1] = 'xxx'
  16. return '.'.join(ip)
  17. partial_ip_address = property(partial_ip_address)
  18. class Score(models.Model):
  19. content_type = models.ForeignKey(ContentType)
  20. object_id = models.PositiveIntegerField()
  21. key = models.CharField(max_length=32)
  22. score = models.IntegerField()
  23. votes = models.PositiveIntegerField()
  24. class Meta:
  25. unique_together = (('content_type', 'object_id', 'key'),)