from datetime import datetime

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from default_settings import RATINGS_USER_MODEL

try:
    from django.utils.timezone import now
except ImportError:
    now = datetime.now

from managers import VoteManager


class Vote(models.Model):
    content_type = models.ForeignKey(ContentType, related_name="votes")
    object_id = models.PositiveIntegerField()
    key = models.CharField(max_length=32)
    score = models.IntegerField()
    user = models.ForeignKey(RATINGS_USER_MODEL, blank=True,
                             null=True, related_name="votes")
    ip_address = models.GenericIPAddressField(unpack_ipv4=True)
    cookie = models.CharField(max_length=32, blank=True, null=True)
    date_added = models.DateTimeField(default=now, editable=False)
    date_changed = models.DateTimeField(default=now, editable=False)

    objects = VoteManager()

    content_object = generic.GenericForeignKey()

    class Meta:
        unique_together = (('content_type', 'object_id', 'key', 'user',
                            'ip_address', 'cookie'))

    def __unicode__(self):
        return u"%s voted %s on %s" % (self.user_display, self.score,
                                       self.content_object)

    def save(self, *args, **kwargs):
        self.date_changed = now()
        super(Vote, self).save(*args, **kwargs)

    def user_display(self):
        if self.user:
            return "%s (%s)" % (self.user.username, self.ip_address)
        return self.ip_address

    user_display = property(user_display)

@@ -1,33 +1,58 @@
-from datetime import datetime
+# coding=utf-8%0Afrom __future__ import unicode_literals
 %0A%0Afr
@@ -78,16 +78,49 @@
  models%0A
+from django.conf import settings%0A
 from dja
@@ -228,320 +228,162 @@
 om d
-efault_settings import RATINGS_USER_MODEL%0A%0Atry:%0A    from django.utils.timezone import now%0Aexcept ImportError:%0A    now = datetime.now%0A%0Afrom managers import VoteManager%0A%0A%0Aclass Vote(models.Model):%0A    content_type = models.ForeignKey(ContentType, related_name=%22votes%22)%0A    object_id = models.PositiveIntegerField()
+jango.utils.encoding import python_2_unicode_compatible%0A%0Afrom ratings.managers import VoteManager%0A%0A%0A@python_2_unicode_compatible%0Aclass Vote(models.Model):
 %0A   
@@ -488,15 +488,21 @@
 Key(
-RATINGS
+settings.AUTH
 _USE
@@ -579,15 +579,15 @@
 ame=
-%22
+'
 votes
-%22
+'
 )%0A  
@@ -750,35 +750,41 @@
 teTimeField(
-default=now
+auto_now_add=True
 , editable=F
@@ -833,19 +833,21 @@
 eld(
-default=now
+auto_now=True
 , ed
@@ -869,33 +869,122 @@
     
-objects = VoteManager
+content_type = models.ForeignKey(ContentType, related_name='votes')%0A    object_id = models.PositiveIntegerField
 ()%0A
-%0A
     
@@ -1029,16 +1029,45 @@
 nKey()%0A%0A
+    objects = VoteManager()%0A%0A
     clas
@@ -1101,16 +1101,29 @@
 ther = (
+%0A            
 ('conten
@@ -1159,31 +1159,16 @@
 'user',%0A
-               
         
@@ -1208,23 +1208,19 @@
   def __
-unicode
+str
 __(self)
@@ -1240,10 +1240,9 @@
 urn 
-u%22
+'
 %25s v
@@ -1254,21 +1254,34 @@
 %25s on %25s
-%22
+'
  %25 (
+%0A            
 self.use
@@ -1306,189 +1306,44 @@
 ore,
-%0A                                       self.content_object)%0A%0A    def save(self, *args, **kwargs):%0A        self.date_changed = now()%0A        super(Vote, self).save(*args, **kwargs)%0A
+ self.content_object)%0A%0A    @property
 %0A   
@@ -1412,17 +1412,17 @@
 urn 
-%22
+'
 %25s (%25s)
-%22
+'
  %25 (
@@ -1493,47 +1493,4 @@
 ess%0A
-%0A    user_display = property(user_display)%0A

Update models.py