Найти - Пользователи
Полная версия: Расшырение админки
Начало » Django » Расшырение админки
1
pikovit
Разшыряю стандартную модель юзера через AUTH_PROFILE_MODULE
from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
GENDER_CHOICES = (
('M', u'Male'),
('F', u'Female'),
)

user = models.ForeignKey(User, unique=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
birthday = models.DateField()
city = models.ForeignKey('City', blank=True)
friends = models.ManyToManyField('self', blank=True)
ratio = models.IntegerField(default=0)

def __unicode__(self):
return self.user

class City(models.Model):
name = models.CharField(max_length=255)
region = models.ForeignKey('Region')

def __unicode__(self):
return '%s (%s)' % (self.name, self.region)

class Region(models.Model):
name = models.CharField(max_length=200)

def __unicode__(self):
return self.name
но когла через адмінку создаю профиль вываливаетса ошыбка:

Exception Type: TypeError
Exception Value: coercing to Unicode: need string or buffer, User found
Александр Кошелев
Поменяйте
    def __unicode__(self):
return self.user
на
    def __unicode__(self):
from django.utils.encoding import force_unicode
return force_unicode(self.user)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB