Прямо сейчас у меня есть код admin.py, который выдает ошибку, когда я пытаюсь использовать django.db.models.User, о котором я догадываюсь https://docs.djangoproject.com/en/dev/topics/auth/. Мой admin.py сейчас читает:
#!/usr/bin/python
# coding=UTF-8
import django.contrib.admin
from django.db.models.signals import post_save
import django.db.models
from pim_accounts.models import UserProfile
django.contrib.admin.autodiscover()
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user = instance)
post_save.connect(create_user_profile, sender = django.db.models.User,
dispatch_uid = 'create_user_profile')
Со всем проектом на http://JonathansCorner.com/project/pim.tgz.
Каков правильный и предпочтительный способ настройки, чтобы pim_accounts.models.UserProfile был установлен как профиль пользователя для всех учетных записей?
Ошибка (плюс настройки среды):
AttributeError at /accounts/login/
'module' object has no attribute 'User'
Request Method: GET
Request URL: http://localhost:8000/accounts/login/?next=/
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value:
'module' object has no attribute 'User'
Exception Location: /Users/jonathan/pim/../pim/admin.py in <module>, line 15
Python Executable: /usr/local/bin/python
Python Version: 2.7.0
Python Path:
['/Users/jonathan/pim',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/pip-0.8.1-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/PIL',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'pim',
'pim_accounts',
'pim_calendar',
'pim_scratchpad']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Server time: Thu, 16 Feb 2012 10:29:54 -0600
Подробное сообщение об ошибке
Traceback:
File "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Users/jonathan/pim/../pim/urls.py" in <module>
2. import admin
File "/Users/jonathan/pim/../pim/admin.py" in <module>
15. post_save.connect(create_user_profile, sender = django.db.models.User,
Exception Type: AttributeError at /accounts/login/
Exception Value: 'module' object has no attribute 'User'