python - django two type of accounts -


i want create 2 type of user account in django 1.6

so following 1 tutorial multiple user types in django >=1.5

from django.db import models django.contrib.auth.models import abstractuser  class customuser(abstractuser):     user = models.onetoonefield(user)     password = models.charfield(     email = models.emailfield(blank=true)  class linkedinuser(customuser):     linkedin_id = models.charfield(max_length=30, unique=true)      class meta:         verbose_name = 'linkedin user'  class facebookuser(customuser):     facebook_id = models.charfield(max_length=30, unique=true)      class meta:         verbose_name = 'facebook user' 

now getting error is:

django.core.exceptions.fielderror: local field 'password' in class 'customuser' clashes field of similar name base class 'abstractuser'

for removing user profile.

class customuser(abstractuser):     pass 

but error is:

(env)refei@user-desktop:~/studio/myproject$ python manage.py syncdb commanderror: 1 or more models did not validate: frontend.profile: accessor m2m field 'groups' clashes related m2m field 'group.user_set'. add related_name argument definition 'groups'. frontend.profile: accessor m2m field 'user_permissions' clashes related m2m field 'permission.user_set'. add related_name argument definition 'user_permissions'. auth.user: accessor m2m field 'groups' clashes related m2m field 'group.user_set'. add related_name argument definition 'groups'. auth.user: accessor m2m field 'user_permissions' clashes related m2m field 'permission.user_set'. add related_name argument definition 'user_permissions'. 

can please guide me, wrong? , how create 2 type of account in django 1.6?

edited after given auth_user_model in admin here error.

commanderror: 1 or more models did not validate: admin.logentry: 'user' has relation model firstapp.customuser, has either not been installed or abstract. auth.user: model has been swapped out 'firstapp.customuser' has not been installed or abstract.

i marking errors in code comments:

class customuser(abstractuser):   # 1     user = models.onetoonefield(user) # 2     password = models.charfield(max_length=30) # 3     email = models.emailfield(blank=true) # 4 

in comment one extending abstructuser model, why adding user onetoone relation in model (in comment two), have use either 1 of those. check: https://docs.djangoproject.com/en/dev/topics/auth/customizing/

comment three , comment four unnecessary here django auth user model provides those(email/password).

for second section:

class customuser(abstractuser):     pass 

you must declare auth_user_model on settings.py. in case:

auth_user_model = 'your_app.customuser' 

Comments


  1. django.core.exceptions.FieldError: Local field 'email' in class 'User' clashes with field of similar name from base class 'AbstractUser'

    class User(AbstractUser):
    username = None
    first_name = None
    last_name = None

    account_no = models.PositiveIntegerField(
    unique=True,
    validators=[
    MinValueValidator(10000000),
    MaxValueValidator(99999999)
    ]
    )

    full_name = models.CharField(
    max_length=256,
    blank=False,
    validators=[
    RegexValidator(
    regex=NAME_REGEX,
    message='Name must be Alphabetic',
    code='invalid_full_name'
    )
    ]
    )

    gender = models.CharField(max_length=6, choices=GENDER_CHOICE)
    birth_date = models.DateField(null=True, blank=True)
    email = models.EmailField(unique=True, blank=False)
    contact_no = models.IntegerField(unique=True)
    Address = models.CharField(max_length=512)
    city = models.CharField(max_length=256)
    country = models.CharField(max_length=256)
    nationality = models.CharField(max_length=256)
    occupation = models.CharField(max_length=256)
    balance = models.DecimalField(
    default=0,
    max_digits=12,
    decimal_places=2
    )
    picture = models.ImageField(
    null=True,
    blank=True,
    height_field="height_field",
    width_field="width_field",
    )

    height_field = models.IntegerField(default=600, null=True)
    width_field = models.IntegerField(default=600, null=True)

    objects = UserManager()

    USERNAME_FIELD = 'email' # use email to log in
    REQUIRED_FIELDS = [] # required when user is created

    def __str__(self):
    return str(self.account_no)



    ReplyDelete
    Replies
    1. I got this error
      django.core.exceptions.FieldError: Local field 'email' in class 'User' clashes with field of similar name from base class 'AbstractUser'

      class User(AbstractUser):
      username = None
      first_name = None
      last_name = None

      account_no = models.PositiveIntegerField(
      unique=True,
      validators=[
      MinValueValidator(10000000),
      MaxValueValidator(99999999)
      ]
      )

      full_name = models.CharField(
      max_length=256,
      blank=False,
      validators=[
      RegexValidator(
      regex=NAME_REGEX,
      message='Name must be Alphabetic',
      code='invalid_full_name'
      )
      ]
      )

      gender = models.CharField(max_length=6, choices=GENDER_CHOICE)
      birth_date = models.DateField(null=True, blank=True)
      email = models.EmailField(unique=True, blank=False)
      contact_no = models.IntegerField(unique=True)
      Address = models.CharField(max_length=512)
      city = models.CharField(max_length=256)
      country = models.CharField(max_length=256)
      nationality = models.CharField(max_length=256)
      occupation = models.CharField(max_length=256)
      balance = models.DecimalField(
      default=0,
      max_digits=12,
      decimal_places=2
      )
      picture = models.ImageField(
      null=True,
      blank=True,
      height_field="height_field",
      width_field="width_field",
      )

      height_field = models.IntegerField(default=600, null=True)
      width_field = models.IntegerField(default=600, null=True)

      objects = UserManager()

      USERNAME_FIELD = 'email' # use email to log in
      REQUIRED_FIELDS = [] # required when user is created

      def __str__(self):
      return str(self.account_no)




      Delete

Post a Comment