django 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

1,430 views
Skip to first unread message

Michael Muster

unread,
Nov 2, 2012, 4:34:18 AM11/2/12
to django...@googlegroups.com
Hi,

I am using django 1.5 and want to add an extra
field to the django user class.
The documentation says that i have to subclass AbstractUser
and add extra fields to it.

So i tried it, in my app 'news' i have:

from django.contrib.auth.models import AbstractUser

class cpUser(AbstractUser):
twitter = models.CharField(max_length=100)
def __unicode__(self):
return self.twitter


and in my settings.py file:

AUTH_USER_MODEL = 'news.cpUser'

however, after running

$ python manage syncdb

i get

NameError: name 'settings' is not defined

What am i doing wrong?



best regards,
Michael

Russell Keith-Magee

unread,
Nov 2, 2012, 4:56:55 AM11/2/12
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Russell Keith-Magee

unread,
Nov 2, 2012, 4:59:35 AM11/2/12
to django...@googlegroups.com
(Apologies for the first reply -- my send button misfired…)

Hi Michael,

It sounds like something else - not related to the your User model - is going wrong with your app; the error about settings doesn't sound like something the auth system would be generating.

Can you run:

./manage syncdb --traceback

so we can get the full context of the error message?

Yours,
Russ Magee %-)

On Fri, Nov 2, 2012 at 4:34 PM, Michael Muster <michael...@googlemail.com> wrote:

Michael Muster

unread,
Nov 2, 2012, 5:11:20 AM11/2/12
to django...@googlegroups.com
On Fri, Nov 02, 2012 at 04:59:35PM +0800, Russell Keith-Magee wrote:
> Can you run:
>
> ./manage syncdb --traceback
>
> so we can get the full context of the error message?
>

Sure, here it is:

:~/www/project$ python manage.py syncdb --traceback
Traceback (most recent call last):
File "/usr/local/bin/django/django/core/management/base.py", line 222, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/bin/django/django/core/management/base.py", line 251, in execute
self.validate()
File "/usr/local/bin/django/django/core/management/base.py", line 277, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/bin/django/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/bin/django/django/db/models/loading.py", line 165, in get_app_errors
self._populate()
File "/usr/local/bin/django/django/db/models/loading.py", line 71, in _populate
self.load_app(app_name, True)
File "/usr/local/bin/django/django/db/models/loading.py", line 95, in load_app
models = import_module('.models', app_name)
File "/usr/local/bin/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/michael/www/project/news/models.py", line 27, in <module>
class News(models.Model):
File "/home/michael/www/project/news/models.py", line 28, in News
author = models.ForeignKey(settings.AUTH_USER_MODEL)
NameError: name 'settings' is not defined
NameError: name 'settings' is not defined


What i forgot in my first post is
that i reference the user model like this:

author = models.ForeignKey(settings.AUTH_USER_MODEL)

So if i remove that line the syncdb command works
just fine.

Raffaele Salmaso

unread,
Nov 2, 2012, 5:15:11 AM11/2/12
to django...@googlegroups.com
On Fri, Nov 2, 2012 at 10:11 AM, Michael Muster
<michael...@googlemail.com> wrote:
> File "/home/michael/www/project/news/models.py", line 28, in News
> author = models.ForeignKey(settings.AUTH_USER_MODEL)
> NameError: name 'settings' is not defined
> NameError: name 'settings' is not defined
did you forget to include
from django.conf import settings
in /home/michael/www/project/news/models.py?

--
| Raffaele Salmaso
| http://salmaso.org
| https://bitbucket.org/rsalmaso
| http://gnammo.com

Michael Muster

unread,
Nov 2, 2012, 5:26:27 AM11/2/12
to django...@googlegroups.com
On Fri, Nov 02, 2012 at 10:15:11AM +0100, Raffaele Salmaso wrote:
> did you forget to include
> from django.conf import settings
> in /home/michael/www/project/news/models.py?
>
> --
> | Raffaele Salmaso

Yep, adding it did it :)

Thanks to both of you!

--
Michael
Reply all
Reply to author
Forward
0 new messages