Commits

Atamert Ölçgen committed 8b0ee15

Fixed #32: made unicode work even before saving

Comments (0)

Files changed (1)

socialregistration/models.py

 
 from django.contrib.auth import authenticate
 from django.contrib.auth.models import User
-from django.contrib.sites.models import Site 
+from django.contrib.sites.models import Site
 
 class FacebookProfile(models.Model):
     user = models.ForeignKey(User)
     site = models.ForeignKey(Site, default=Site.objects.get_current)
     uid = models.CharField(max_length=255, blank=False, null=False)
-    
+
     def __unicode__(self):
-        return u'%s: %s' % (self.user, self.uid)
-    
+        if self.pk:
+            user = self.user
+        else:
+            user = u'<no-user>'
+        return u'%s: %s' % (user, self.uid)
+
     def authenticate(self):
         return authenticate(uid=self.uid)
 
     user = models.ForeignKey(User)
     site = models.ForeignKey(Site, default=Site.objects.get_current)
     twitter_id = models.PositiveIntegerField()
-    
+
     def __unicode__(self):
         return u'%s: %s' % (self.user, self.twitter_id)
-    
+
     def authenticate(self):
         return authenticate(twitter_id=self.twitter_id)
 
     user = models.ForeignKey(User)
     site = models.ForeignKey(Site, default=Site.objects.get_current)
     identity = models.TextField()
-    
+
     def __unicode__(self):
         return u'OpenID Profile for %s, via provider %s' % (self.user, self.identity)