Django TinyMCE: 'ModelFormMetaclass' object is not iterable - python

I'm currently working with the Django framework to build a content management system into a company website, and after successfully completing one page, began work on a different page that requires a rich text editor within the admin interface.
Having chosen TinyMCE for the job, I spent a lot of time on Monday trying to get it running correctly, but only managed to include a simple HTMLField(). Having been slightly confused by a number of differing tutorials, I've now encountered an error that I'm struggling to find a solution to, and one which I hoped the StackOverflow community might be able to help with.
Currently, I have the following code:
admin.py
from django.forms import *
from django.db.models import *
from tinymce.widgets import TinyMCE
from models import *
from django.contrib import admin
#class MyModelForm(forms.ModelForm):
#content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#class Meta:
#model = MyModel
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
admin.site.register(MyModelForm, MyModelAdmin)
The majority of this code has been commented out for debugging purposes, as the problem seems to be with models.py:
models.py
from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE
class MyModelForm(forms.ModelForm):
content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows' : 30}))
class Meta:
model = FlatPage
This is the traceback I'm being presented with:
Environment:
Request Method: GET
Request URL: mycomputer.mydomain/company/admin/
Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'cms.plugins.file',
'cms.plugins.link',
'cms.plugins.picture',
'cms.plugins.text',
'reversion',
'grappelli',
'profiles',
'tinymce',
'testapp',
'django_reset')
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',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/companycms/urls.py" in <module>
7. admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/testapp/admin.py" in <module>
17. admin.site.register(MyModelForm, MyModelAdmin)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in register
77. for model in model_or_iterable:
Exception Type: TypeError at /admin/
Exception Value: 'ModelFormMetaclass' object is not iterable
As you can see, tinymce appears to be correctly installed, and the problem lies with models.ModelForm
My aim, in case it isn't clear, is to create a simple MyModel model with one content field, editable using the TinyMCE Editor. If you think I could supply any more code to shed more light on the situation, please let me know. Thanks.

I think I'm a bit confused with your model definition, either way I think your error is in this line
admin.site.register(MyModelForm, MyModelAdmin)
unless I'm being fooled by the name MyModelForm you are passing a ModelForm to the register method which takes a models.Model subclass as an argument.

This is really late to the party but this is what you need.
admin.site.register(MyModel, MyModelAdmin)
The MyModelAdmin has the MyModelForm and admin.site.register takes a Model and a ModelAdmin

Related

Detecting and correcting Circular Imports

So, this is an extension of what I asked last week (Why do I need to import a class within this class, instead of at the top of the file?) but after extensive debugging, I feel like it might warrant a new question.
I have a number of modules, all with imports. I suspect there may be a circular import but I haven't been able to find it.
Here's the weird thing:
In one models.py file, I have:
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from heythere.models import Notification as HeyThere
from heythere.models import NotificationManager as HeyThereManager
from django.contrib.auth.models import User
then some model definitions, including one with a method:
def to_user(self):
try:
return User.objects.get(username=str(self.username))
except ObjectDoesNotExist:
return None
and a little further down:
from ownership.apps.Assets.models import Item
When it's like this, I get AttributeError: 'NoneType' object has no attribute 'objects' (referring to User). So it's set to None, somehow, as opposed to raising a global name XXX is not defined.
BUT THEN, I tried accessing the User right after the import:
me = User.objects.get(username='xxxx')
print me
It printed correctly upon running runserver, so I know it can access User there, but then gave me the error message ImportError: cannot import name Item. How did simply accessing the model cause an import error? (FWIW, Item does have a number of FK relations to User)
What gives?
Traceback when User.objects.get() is included:
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
self.validate(display_num_errors=True)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/models.py", line 12, in <module>
import permissions
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/permissions.py", line 4, in <module>
from ownership.apps.Shared.models import Person
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py", line 87, in <module>
from ownership.apps.Assets.models import Item
ImportError: cannot import name Item
And without (how the code should work):
Environment:
Request Method: POST
Request URL: http://localhost:8000/application/new
Django Version: 1.6.1
Python Version: 2.7.2
Installed Applications:
('suit',
'south',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.redirects',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'rest_framework',
'ldap_sync',
'crispy_forms',
'ownership.apps.Catalog',
'ownership.apps.Assets',
'ownership.apps.Shared',
'ownership.libs.display',
'django_tables2',
'haystack',
'autocomplete_light',
'reversion',
'heythere',
'polymorphic',
'django_extensions',
'debug_toolbar')
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',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
'ownership.libs.shibboleth.CustomHeaderMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/crud_views.py" in connect_create_view
48. return subview.as_view()(request, model_name=model_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/crud_views.py" in post
280. create_new_asset_notification(request, new_item)
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/views.py" in create_new_asset_notification
123. send_email(request, subject, body, owner.to_user().email, )
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py" in to_user
52. return User.objects.get(username=str(self.username))
Exception Type: AttributeError at /application/new
Exception Value: 'NoneType' object has no attribute 'objects'
Note this in my stack trace:
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/models.py", line 12, in <module>
import permissions File "/Users/xxxxx/code/ownership/ownership/apps/Assets/permissions.py", line 4, in <module>
from ownership.apps.Shared.models import Person File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py", line 87, in <module>
from ownership.apps.Assets.models import Item
Assets/models.py was importing permissions
Permissions was importing Shared.models.Person
Shared/models was importing Assets.models.Item
which was a circular import.
This was corrected by moving from django.contrib.auth.models import User to inside of the Person model. I don't quite understand why--if anyone wants to elaborate and provide a better explanation before I accept my own answer, please do.

Using a variable as a Model Lookup

I am passing in a variable to my view which is the name of the model to be queried against.
model_name = 'application'
assets = model_name.objects.all()
I get the error that unicode objects don't have objects properties, which makes sense as my debugger shows model_name = u'application' as expected (not as wanted).
I figure it has to do with *args and **kwargs (which I'm new to, but think I get) especially since elsewhere in my code I have:
role_set = ['primary_tech', 'primary_biz', 'backup_tech', 'backup_biz']
for role in role_set:
records_to_change = Item.objects.filter(**{role:old_owner})
which works fine. I tried every combination of * and ** I could think of, as well as wrapping it in a for model_name in [model_name] for consistency's sake, and everything gives me a syntax error. What am I missing?
Python 2.7, Django 1.5
Traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/application/all/
Django Version: 1.6.1
Python Version: 2.7.2
Installed Applications:
('suit',
'south',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.redirects',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'rest_framework',
'ldap_sync',
'crispy_forms',
'ownership.apps.Catalog',
'ownership.apps.Assets',
'ownership.apps.Shared',
'ownership.libs.display',
'django_tables2',
'haystack',
'autocomplete_light',
'reversion',
'debug_toolbar')
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',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
'ownership.libs.shibboleth.CustomHeaderMiddleware',
'ownership.libs.middleware.LoginRequiredMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
90. response = middleware_method(request)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/Users/nicholsp/code/ownership/ownership/urls.py" in <module>
27. url(r'^', include('ownership.apps.Assets.urls'), name='home'),
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
26. urlconf_module = import_module(urlconf_module)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/Users/nicholsp/code/ownership/ownership/apps/Assets/urls.py" in <module>
3. import views
Exception Type: SyntaxError at /application/all/
Exception Value: invalid syntax (views.py, line 132)
from django.db.models import get_model
class MyModel(models.Model):
...
model_class = get_model('myapp', 'mymodel')
print model_class.__name__
'MyModel'
model_class.objects.all()
[<MyModel: 1>, <MyModel: 2>, <MyModel: 3>, ... ]

ImproperlyConfigured at / 'ClientEventLogAdmin.exclude' refers to field 'created' that is missing from the form

I am installing a django application module.I am getting this error.
I started another MicroInstance and reinstalled everything but still I am getting this error.
.
Environment:
Request Method: GET
Request URL: http://54.235.127.252/mds/
Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['sana.mrs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'sana.mrs.util.LoggingMiddleware')
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/opt/sana/urls.py" in <module>
12. admin.autodiscover()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
26. import_module('%s.admin' % app)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/opt/sana/mrs/admin.py" in <module>
26. admin.site.register(ClientEventLog, ClientEventLogAdmin)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in register
97. validate(admin_class, model)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in validate
24. validate_base(cls, model)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in validate_base
279. check_formfield(cls, model, opts, 'exclude', field)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in check_formfield
369. "is missing from the form." % (cls.__name__, label, field))
Exception Type: ImproperlyConfigured at /
Exception Value: 'ClientEventLogAdmin.exclude' refers to field 'created' that is missing from the form.
Note:I just need to install this application.I am intermediate in python.and beginner in Django.But professional in PHP,mysql and front end with jQuery
From what I see, the problem is likely to be related to the moca framework.
If your /opt/sana/mrs/admin.py file looks like this then the culprit is likely to be located at line 12 : the created field is refered in the exclude list, but not previously defined.
As I'm not sure about your needs here are some solutions you can try :
Re-install or update your moca frameword ;
Add a piece of code before the execute definition (not sure what's type it should be though) :
from django.db import models # You may also place it in the top of the file
created = models.DateField(blank=True, null=True)
Remove the created item from the exclude list (not sure about the impact though)
Hope it helps,

Can't find View in Django

I am getting the error
ViewDoesNotExist at /
Could not import blog.views. View does not exist in module blog.
With Django
My URLS file looks like this
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'blog.views.home', name='home'),
# url(r'^Blog/', include('Blog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
and my directory tree looks like this
Blog
_manage.py
_Blog
__wsgi.py
__urls.py
__settings.py
__ __init__.py
_blog
__views.py
__tests.py
__Templates
____index.html
__models.py
__ __init__.py
And in the views.py
from django.shortcuts import render_to_response
from blog.models import posts
def home(request):
return render_to_response('index.html')
Further Debugging:
Environment:
Request Method: GET
Request URL: http://192.168.2.3:1337/
Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles')
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')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
300. sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
209. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in callback
216. self._callback = get_callable(self._callback_str)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in wrapper
27. result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in get_callable
101. (lookup_view, mod_name))
Exception Type: ViewDoesNotExist at /
Exception Value: Could not import blog.views. View does not exist in module blog.
Based on your debugging output it seems that the blog application isn't present in your INSTALLED_APPS setting in settings.py
Apparently you forgot include your 'blog' application into django installed applications on settings.py
Check capitalization in your naming and also make sure you have an init.py in your app.

What is the proper way to register a user profile?

Right now I have in my admin.py code which is generating an error when I try to use django.db.models.User which is where I'm guessing https://docs.djangoproject.com/en/dev/topics/auth/ is talking about. My admin.py presently reads:
#!/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')
With the whole project at http://JonathansCorner.com/project/pim.tgz.
What is the correct and preferred way of setting things so that a pim_accounts.models.UserProfile is set as the user profile for all accounts?
The error (plus environment settings) is:
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
Detailed Error Message
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'
I just use User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]). This will create a profile when you try to access user.profile if it doesn't exist. You should also set AUTH_PROFILE_MODULE to the model you're using for profiles in settings.py.
Looks like you're trying to import User from django.db.models rather than django.contrib.auth.models, try:
from django.contrib.auth.models import User
post_save.connect(create_user_profile, sender=User,
dispatch_uid='create_user_profile')

Categories

Resources