Tuesday, September 28, 2010

Re: User.get_profile() not working

Good grief. After spending hours trying to figure out what was wrong,
I immediately found the problem after making this post. Here's the
solution:

I had overridden UserProfile.__init__() like this:

class UserProfile(models.Model):
def __init__(self, website='http://www.default.com'):

while its superclass looks like this:
class Model(object):
...
def __init__(self, *args, **kwargs):

Somewhere deep inside Django the 'model.__init__()' was being called
to create a UserProfile passing it a bunch of parameters it was not
prepared to accept. So I just changed it to:

class UserProfile(models.Model):
def __init__(self, website='http://www.default.com', *args,
**kwargs):

... and all was well. That explained the 'TypeError: __init__() takes
at most 2 arguments (4 given) ' message.

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

No comments:

Post a Comment