Jerome
Jerome

Reputation: 67

inheritance from the django user model results in error when changing password

I inherited form the django user model like so:

from django.db import models
from django.contrib.auth.models import User, UserManager
from django.utils.translation import ugettext_lazy as _

class NewUserModel(User):
    custom_field_1 = models.CharField(_('custom field 1'), max_length=250, null=True, blank=True)
    custom_field_2 = models.CharField(_('custom field 2'), max_length=250, null=True, blank=True)

    objects = UserManager()

When i go to the admin and add an entry into this model, it saves fine, but below the "Password" field where it has this text "Use '[algo]$[salt]$[hexdigest]' or use the change password form.", if i click on the "change password form' link, it produces this error

Truncated incorrect DOUBLE value: '7/password'

What can i do to fix this?

Upvotes: 1

Views: 480

Answers (2)

Vasil
Vasil

Reputation: 38136

While doable (I did it once and regret it) using inheritance to extend the User model is not the best idea. I'd suggest you take Chris' advice and extend the User model with 1-1 relationship as it is the "standard" and "supported" way of doing it, and the way reusable apps deal with user profiles. Otherwise you need to implement an authentication backend if you want to do it by inheritance. So if you MUST do it see this. But be warned, you'll stumble across other problems later.

Upvotes: 0

Chris Lawlor
Chris Lawlor

Reputation: 48972

The best way to extend Django's User model is to create a new Profile model and identify it through the AUTH_PROFILE_MODULE setting. See http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/, and http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

This adds a get_profile() method to User instances which retrieves your associated model for a given User.

Upvotes: 1

Related Questions