Setting up two different types of Users in Django 1.5/1.6

前端 未结 3 419
孤街浪徒
孤街浪徒 2021-01-30 09:51

Please note--this is an updated version of my original question on this subject, but deserves to be asked again with the change in how Django deals with users and authentica

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 10:26

    1. Create a BaseUser which extends Django's Abstract base User
    2. Create two Sub Classes Named CustomerUser and StoreOwnerUser which extends BaseUser

      from django.db import models
      from django.contrib.auth.models import AbstractUser
      
      class BaseUser(AbstractUser):
          # all the common fields go here, for example:
          email = models.EmailField(max_length=10,unique=True)
          name = models.CharField(max_length=120)
      
      class StoreOwnerUser(BaseUser):
          # All Store Owner specific attribute goes here
          balance = models.some_balance_field()
          stores_owned = models.some_stores_owned_field()
      
          class Meta:
          verbose_name = 'Store Owner'
      
      class CustomerUser(BaseUser):
          # All Customer specific attribute goes here
          customer_id = models.CharField(max_length=30, unique=True)
          address =  models.some_address
          time_zone = models.something...
          ...
      
          class Meta:
              verbose_name = 'Customer'
      

提交回复
热议问题