Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango problems with id in custom UserModel
    text
    copied!<p>I need to use user_id instead id in my custom user model(don't ask why, it's a long story :)). I try to use code from django example, but when it I tried to log in into admin backend, I got In template site-packages/django/contrib/admin/templates/admin/index.html, error at line 60 'User' object has no attribute 'id'</p> <p>Line with error looks like </p> <pre><code>{% get_admin_log 10 as admin_log for_user user %} #UserManager class UserManager(BaseUserManager): def create_user(self, login_name, email, first_name, last_name, password=None): if not email: raise ValueError('The given email must be set') email = UserManager.normalize_email(email) user = self.model(login_name=login_name, email=email, first_name=first_name, last_name=last_name, is_staff=False, is_active=True, is_superuser=True) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, login_name, email, first_name, last_name, password): u = self.create_user(login_name, email, first_name, last_name, password) u.is_staff = True u.is_active = True u.is_superuser = True u.save(using=self._db) return u #Model class User(AbstractBaseUser, PermissionsMixin): user_id = models.AutoField(primary_key=True) login_name = models.CharField(max_length=30, unique=True, db_index=True) email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=128) last_name = models.CharField(max_length=128) phone = models.CharField(max_length=128) objects = UserManager() USERNAME_FIELD = 'login_name' REQUIRED_FIELDS = ['email', 'first_name', 'last_name'] is_staff = models.BooleanField('staff status', default=False) is_active = models.BooleanField('active', default=True) def get_full_name(self): full_name = '%s %s' % (self.first_name, self.last_name) return full_name.strip() def get_short_name(self): return self.first_name #Admin from django.contrib import admin from applications.users.models import User class UserAdmin(admin.ModelAdmin): list_display = ('login_name', 'email', 'first_name', 'last_name') admin.site.register(User, UserAdmin) </code></pre> <p>How can I fix it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload