0

나는 새로운 사용자를 추가 할 때 사용자 지정 사용자 모델과 관리장고 사용자 정의 사용자의 모델과 UserAdmin - Programmin 오류 새 사용자

# models.py 

from django.db import models 
from django.contrib.auth.models import AbstractUser 


class Employee(AbstractUser): 

    class Meta: 
     verbose_name = 'Employee' 
     verbose_name_plural = 'Employees' 


# settings.py 
AUTH_USER_MODEL = 'myapp.Employee' 


# admin.py 

from django.contrib import admin 
from django.contrib.auth.admin import UserAdmin 

from myapp.models import Employee 


admin.site.register(Employee, UserAdmin) 

음을 사용하는 동안 나는 몇 가지 문제에 봉착를 추가하는 동안, 그것을 날이 오류를 trows :

Environment: 


Request Method: POST 
Request URL: http://127.0.0.1:8050/admin/chaos/employee/add/ 

Django Version: 1.7.1 
Python Version: 2.7.6 
Installed Applications: 
['admin_tools', 
'admin_tools.theming', 
'admin_tools.menu', 
'admin_tools.dashboard', 
'django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django_extensions', 
'reversion', 
'mptt', 
'imperavi', 
'django_mptt_admin', 
'document', 
'chaos'] 
Installed Middleware: 
['django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware'] 


Traceback: 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 
    111.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 
    584.     return self.admin_site.admin_view(view)(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 
    105.      response = view_func(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 
    52.   response = view_func(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 
    204.    return view(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 
    29.    return bound_func(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper 
    76.    return view(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 
    25.     return func.__get__(self, type(self))(*args2, **kwargs2) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 
    29.    return bound_func(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 
    105.      response = view_func(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 
    25.     return func.__get__(self, type(self))(*args2, **kwargs2) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner 
    394.     return func(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/auth/admin.py" in add_view 
    121.            extra_context) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view 
    1454.   return self.changeform_view(request, None, form_url, extra_context) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 
    29.    return bound_func(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 
    105.      response = view_func(request, *args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 
    25.     return func.__get__(self, type(self))(*args2, **kwargs2) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner 
    394.     return func(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view 
    1397.    if form.is_valid(): 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid 
    162.   return self.is_bound and not bool(self.errors) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in errors 
    154.    self.full_clean() 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean 
    353.   self._clean_fields() 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields 
    371.      value = getattr(self, 'clean_%s' % name)() 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py" in clean_username 
    101.    User._default_manager.get(username=username) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method 
    92.     return getattr(self.get_queryset(), name)(*args, **kwargs) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in get 
    351.   num = len(clone) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__ 
    122.   self._fetch_all() 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all 
    966.    self._result_cache = list(self.iterator()) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator 
    265.   for row in compiler.results_iter(): 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter 
    700.   for rows in self.execute_sql(MULTI): 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql 
    786.    cursor.execute(sql, params) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute 
    81.    return super(CursorDebugWrapper, self).execute(sql, params) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute 
    65.     return self.cursor.execute(sql, params) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__ 
    94.     six.reraise(dj_exc_type, dj_exc_value, traceback) 
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute 
    65.     return self.cursor.execute(sql, params) 

Exception Type: ProgrammingError at /admin/chaos/employee/add/ 
Exception Value: relation "auth_user" does not exist 
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user... 

누구나가 같은 것을하고 그것을 해결하기 위해 어떤 힌트를 경험?

은 내가 원래 UserAdmin에 의해 사용되는 UserCreationFormUserChangeForm을 하위 클래스도 필요 용의자를했지만, 그것은 올바른 방법 인 경우, 나는 정직을 만들 오히려 사용자 정의 사용자 모델을 사용의 이점을 볼 수 없습니다 원래 사용자를 확장하기위한 일대일 모델 (예 : Profile).

감사 루카

답변

-4

좋은 하루, 루크!

는, 장고 문서를보고하십시오 :

https://docs.djangoproject.com/en/dev/topics/auth/customizing/ 그냥 확인, 사용하고있는 모델 : CustomUser 또는 추상 자료 사용자. 알 수 있듯이 이제는 초록 사용자입니다.

+0

django docs : "Django의 사용자 모델에 만족하고 추가 프로필 정보를 추가하기 만하면 django.contrib.auth.models.AbstractUser를 하위 클래스로 만들고 사용자 정의 프로필 필드를 추가 할 수 있습니다. 커스텀 사용자 모델 지정의 "모델 디자인 고려 사항"노트에 설명 된 별도의 모델을 권장하지만, AbstractUser는 추상적 인 모델로 기본 사용자의 전체 구현을 제공합니다. " 어쨌든 사용자 정의 사용자 모델에 적합한 사용자 정의 관리자를 지정하여 해결되었습니다. – Luke

+1

동의 해주세요! 내 잘못이야. 죄송합니다. 어쨌든, 제 경우에는 OneToOneField를 사용하는 것을 선호합니다. – NONAMA