Good day, I have two user forms which I'm using depending on the cases.
美好的一天,我有两个用户表格,我根据具体情况使用。
I'm having the following error, but not sure why:
我有以下错误,但不确定原因:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fc7c8e48378>
Traceback (most recent call last):
File "/home/drcongo/.virtualenvs/store/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/drcongo/.virtualenvs/store/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/home/drcongo/.virtualenvs/store/lib/python3.4/site-packages/django/core/management/base.py", line 472, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'accounts.admin.UserAdmin'>: (admin.E019) The value of 'filter_horizontal[0]' refers to 'groups', which is not an attribute of 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E019) The value of 'filter_horizontal[1]' refers to 'user_permissions', which is not an attribute of 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'email', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'last_name', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E108) The value of 'list_display[4]' refers to 'is_staff', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'accounts.StoreOwner'.
<class 'accounts.admin.UserAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'is_staff', which does not refer to a Field.
<class 'accounts.admin.UserAdmin'>: (admin.E116) The value of 'list_filter[1]' refers to 'is_superuser', which does not refer to a Field.
<class 'accounts.admin.UserAdmin'>: (admin.E116) The value of 'list_filter[2]' refers to 'is_active', which does not refer to a Field.
<class 'accounts.admin.UserAdmin'>: (admin.E116) The value of 'list_filter[3]' refers to 'groups', which does not refer to a Field.
Here are my models:
这是我的模特:
from django.contrib.auth.models import AbstractUser
from django.db import models
# Create your models here.
from store.models import Category
class PrimaryUser(AbstractUser):
"""
Model to create, and register users.
"""
def __str__(self):
return [self.username]
class StoreOwner(models.Model):
"""
Model to create, and register store.
"""
username = models.ForeignKey(PrimaryUser)
store_name = models.ForeignKey('Store', max_length=50)
def __str__(self):
return " ".join([self.username, self.store_name])
class Store(models.Model):
store_name = models.CharField(max_length=50)
category = models.ManyToManyField(Category)
and in my settings:
在我的设置中:
AUTH_USER_MODEL = 'accounts.PrimaryUser'
and admin.py:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import StoreOwner
@admin.register(StoreOwner)
class UserAdmin(UserAdmin):
list_display = list(UserAdmin.list_display) + [
'store_name',
]
and my forms:
和我的表格:
from django import forms
from django.utils.translation import ugettext as _
from .models import StoreOwner, PrimaryUser
class StoreOwnerForm(forms.ModelForm):
password1 = forms.CharField(label="password", widget=forms.PasswordInput)
password2 = forms.CharField(label="confirm password", widget=forms.PasswordInput)
error_messages = {
'password_mismatch': _('Your password didn\'t match'),
}
class Meta:
model = StoreOwner
fields = [
'username',
'store_name',
'password1',
'password2',
]
help_texts = {
'username': None,
}
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
return password2
class PrimaryUserForm(forms.ModelForm):
password1 = forms.CharField(label="password", widget=forms.PasswordInput)
password2 = forms.CharField(label="confirm password", widget=forms.PasswordInput)
error_messages = {
'password_mismatch': _('Your password didn\'t match'),
}
class Meta:
model = PrimaryUser
fields = [
'username',
'password1',
'password2',
]
help_texts = {
'username': None,
}
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
return password2
will really appreciate any help
真的很感激任何帮助
1 个解决方案
#1
0
Your StoreOwner
doesn't have any AbstractUser
or PrimaryUser
fields, yet you register it to a User admin:
您的StoreOwner没有任何AbstractUser或PrimaryUser字段,但您将其注册到用户管理员:
@admin.register(StoreOwner)
class UserAdmin(UserAdmin):
You can do two things:
你可以做两件事:
-
Register
StoreOwner
to a normal ModelAdmin and add the user as inline admin. See docs.将StoreOwner注册到普通的ModelAdmin并将用户添加为内联管理员。查看文档。
-
Let
StoreOwner
extendPrimaryUser
in stead of using a primary key.让StoreOwner扩展PrimaryUser而不是使用主键。
#1
0
Your StoreOwner
doesn't have any AbstractUser
or PrimaryUser
fields, yet you register it to a User admin:
您的StoreOwner没有任何AbstractUser或PrimaryUser字段,但您将其注册到用户管理员:
@admin.register(StoreOwner)
class UserAdmin(UserAdmin):
You can do two things:
你可以做两件事:
-
Register
StoreOwner
to a normal ModelAdmin and add the user as inline admin. See docs.将StoreOwner注册到普通的ModelAdmin并将用户添加为内联管理员。查看文档。
-
Let
StoreOwner
extendPrimaryUser
in stead of using a primary key.让StoreOwner扩展PrimaryUser而不是使用主键。