Форум сайта python.su
Всем привет.
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
django.VERSION
(1, 8, 13, ‘final’, 0)
бд postgresql_psycopg2
Есть Кастомная модель.
settings.py
INSTALLED_APPS = ( ... 'portal_users', ) AUTH_USER_MODEL = 'portal_users.PortalUser'
class PortalUserManager(BaseUserManager): def create_user(self, password, email): """ Creates and saves a User with the given username, password, email, created_a birth and password. """ #if not username: # raise ValueError('Users must have a username') if not email: raise ValueError('Users must have an email address') user = self.model( #username=username, email=self.normalize_email(email), ) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, password, email): user = self.create_user(password, email) user.save(using=self._db) return user class PortalUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField('email address', unique=True) first_name = models.CharField('first name', max_length=50, blank=True) last_name = models.CharField('last name', max_length=50, blank=True) is_staff = models.BooleanField('staff status', default=False, help_text='Designates whether the user can log into this admin site.') is_active = models.BooleanField('active', default=True, help_text=('Designates whether this user should be treated as ' 'active. Unselect this instead of deleting accounts.')) ... куча своих полей def get_full_name(self): ... def get_short_name(self): ... USERNAME_FIELD = 'email' created_at = models.DateTimeField(auto_now_add=True) REQUIRED_FIELDS = [] objects = PortalUserManager()
from django.contrib import admin from portal_users.models import PortalUser class PortalUserAdmin(admin.ModelAdmin): list_display = [ ... ] list_filter = [ ... ] admin.site.register(PortalUser, PortalUserAdmin)
Офлайн
Решение нашел тут:
https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#a-full-example
Можно закрывать.
Офлайн