I am trying to extend the default User Model in django.
I have defined a class called Profile.
# code in myapp/models/profile.py
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User)
field = models.CharField(max_length=30)
class Meta:
app_label="myapp"
In my view function I invoke a method where I get an exception:
def my_view_function(request):
field = get_field(request.user)
...
def get_field(user):
return user.profile.field
# also tried return user.get_profile().field with AUTH_PROFILE_MODULE in settings.py set to "myapp.Profile", still does not work.
I get an AttributeError in my stacktrace 'unicode' object has no attribute 'get_profile'
or 'unicode' object has no attribute 'profile'
.
When I try to concatenate the user object in get_field() with a string I get an error saying 'str' cannot concatenate with 'SimpleLazyObject'
.
I tried reading request.user returns a SimpleLazyObject, how do I "wake" it? but that did not help.
I am using middleware to ensure that the user is logged in so I am sure that the user is logged in. What is wrong with the user object? Why does it django say user object has '__unicode__'
type.
Thanks in Advance!