Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/accounts/user/None/change/
Raised by: django.contrib.admin.options.change_view
Аккаунт с первичным ключом 'None' не существует.
Переопределил встроенную модель, при попытке добавить новый аккаунт возникает ошибка. Пробую добавить пользователя из админки. Изначально все работало, создал несколько юзеров.
Добавил несколько новых приложений в проект. Решил проверить как создаются аккаунты и на тебе.
models.py
class User(AbstractBaseUser):
firstname = models.CharField(
verbose_name='Имя',
max_length=50,
blank=True,
null=True,
)
lastname = models.CharField(
verbose_name='Фамилия',
max_length=100,
blank=True,
null=True,
)
email = models.EmailField(
verbose_name='Электронный адресс',
max_length=255,
unique=True,
)
dental_office = models.CharField(
max_length=255,
verbose_name='Название стоматологии',
blank=True,
null=True,
)
photo = models.ImageField(upload_to='logo/', verbose_name="Фотография пользователя", null=True, blank=True)
photo_thumbnail = ImageSpecField(source='photo',
processors=[ResizeToFill(48, 48)],
format='JPEG',
options={'quality': 60})
created_date = models.DateTimeField(
auto_now_add=True,
verbose_name='Дата создания',
)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['password']
class Meta:
verbose_name = 'Аккаунт'
verbose_name_plural = 'Аккаунты'
swappable = 'AUTH_USER_MODEL'
def get_full_name(self):
# The user is identified by their email address
return self.email
def get_fulname(self):
return "%s %s" % (self.firstname, self.lastname)
def get_short_name(self):
# The user is identified by their email address
return self.email
def __str__(self): # __unicode__ on Python 2
return self.email
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
def save (self, **kwargs):
if not self.id:
return
super(User, self).save()
@property
def is_staff(self):
"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
return self.is_admin
forms.py
class AccountCreateForm(forms.ModelForm):
class Meta:
model = User
fields = ['firstname', 'lastname', 'email', 'password']
widgets = {
'firstname': forms.TextInput(attrs={'class': 'form-control', 'maxlength': '50', 'placeholder': 'Имя'}),
'lastname': forms.TextInput(attrs={'class': 'form-control', 'maxlength': '100', 'placeholder': 'Фамилия'}),
'email': forms.EmailInput(
attrs={'class': 'form-control', 'maxlength': '100', 'placeholder': 'Электронная почта'}),
'password': forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Задайте пароль'}),
}
views.py
class AccountCreateView(CreateView):
model = User
template_name = 'accounts/register.html'
form_class = AccountCreateForm
success_url = '/'