1

I know partial inheriting it is not possible. I need to create a user model for my Django apps, for that I want to use the User class defined in Django. But I do not need the username field, which is set as required.

Suppose I inherit from User to MyUser. Is it possible to delete the username attribute in MyUser. i.e. del MyUser.username? Or can someone suggest other way to do this?

2
  • 1
    keep it as it is . set email in username field . Or u have to modify auth module . Commented Mar 10, 2014 at 10:57
  • 1
    Setting e-mail in username field has its own problems (like maxlength). You can put user_id into username if necessary. Commented Mar 10, 2014 at 10:59

2 Answers 2

2

The AbstractBaseUser class is made specifically for this scenario. Inherit from this class and define your own fields, and be sure to set the USERNAME_FIELD attribute to your email field.

Sign up to request clarification or add additional context in comments.

Comments

1

The username field is required - otherwise users cannot login.

If you want to have an email address as the username - starting from django 1.5, you can create your own custom user model which will work just like the default model that comes with django.

In this custom user model, set the USERNAME_FIELD property to the name of the column that you want to use for the username. This column must be unique.

There is a lot of work you have to do, and really this should be done at the start of your project as these changes require database updates.

You should read the documentation to get started.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.