1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

unicode: Fixed #4109 -- Converted internal models to have a __unicode__ method.

In most cases this is just a slight performance improvement (saves on later
conversions), in a few cases it's a good idea because things like
"username" could now be legitimately non-ASCII.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5059 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-04-22 04:55:42 +00:00
parent 03b46fc8d0
commit dfe20bb91a
5 changed files with 13 additions and 13 deletions

View File

@ -45,8 +45,8 @@ class Permission(models.Model):
unique_together = (('content_type', 'codename'),) unique_together = (('content_type', 'codename'),)
ordering = ('content_type', 'codename') ordering = ('content_type', 'codename')
def __str__(self): def __unicode__(self):
return "%s | %s | %s" % (self.content_type.app_label, self.content_type, self.name) return u"%s | %s | %s" % (self.content_type.app_label, self.content_type, self.name)
class Group(models.Model): class Group(models.Model):
"""Groups are a generic way of categorizing users to apply permissions, or some other label, to those users. A user can belong to any number of groups. """Groups are a generic way of categorizing users to apply permissions, or some other label, to those users. A user can belong to any number of groups.
@ -66,7 +66,7 @@ class Group(models.Model):
class Admin: class Admin:
search_fields = ('name',) search_fields = ('name',)
def __str__(self): def __unicode__(self):
return self.name return self.name
class UserManager(models.Manager): class UserManager(models.Manager):
@ -122,7 +122,7 @@ class User(models.Model):
list_filter = ('is_staff', 'is_superuser') list_filter = ('is_staff', 'is_superuser')
search_fields = ('username', 'first_name', 'last_name', 'email') search_fields = ('username', 'first_name', 'last_name', 'email')
def __str__(self): def __unicode__(self):
return self.username return self.username
def get_absolute_url(self): def get_absolute_url(self):
@ -262,7 +262,7 @@ class Message(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
message = models.TextField(_('message')) message = models.TextField(_('message'))
def __str__(self): def __unicode__(self):
return self.message return self.message
class AnonymousUser(object): class AnonymousUser(object):
@ -272,8 +272,8 @@ class AnonymousUser(object):
def __init__(self): def __init__(self):
pass pass
def __str__(self): def __unicode__(self):
return 'AnonymousUser' return u'AnonymousUser'
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, self.__class__) return isinstance(other, self.__class__)

View File

@ -42,7 +42,7 @@ class ContentType(models.Model):
ordering = ('name',) ordering = ('name',)
unique_together = (('app_label', 'model'),) unique_together = (('app_label', 'model'),)
def __str__(self): def __unicode__(self):
return self.name return self.name
def model_class(self): def model_class(self):

View File

@ -26,8 +26,8 @@ class FlatPage(models.Model):
list_filter = ('sites',) list_filter = ('sites',)
search_fields = ('url', 'title') search_fields = ('url', 'title')
def __str__(self): def __unicode__(self):
return "%s -- %s" % (self.url, self.title) return u"%s -- %s" % (self.url, self.title)
def get_absolute_url(self): def get_absolute_url(self):
return self.url return self.url

View File

@ -20,5 +20,5 @@ class Redirect(models.Model):
list_filter = ('site',) list_filter = ('site',)
search_fields = ('old_path', 'new_path') search_fields = ('old_path', 'new_path')
def __str__(self): def __unicode__(self):
return "%s ---> %s" % (self.old_path, self.new_path) return u"%s ---> %s" % (self.old_path, self.new_path)

View File

@ -19,5 +19,5 @@ class Site(models.Model):
list_display = ('domain', 'name') list_display = ('domain', 'name')
search_fields = ('domain', 'name') search_fields = ('domain', 'name')
def __str__(self): def __unicode__(self):
return self.domain return self.domain