Multiple User Types In Django

前端 未结 3 713
一生所求
一生所求 2021-01-15 09:34

I am new to Django and trying to create an App with two User Types (Freelancers and Customers). I understand how to create a User profile Class and it works well for me:

3条回答
  •  情话喂你
    2021-01-15 09:54

    You could try this:

    class UserProfile(models.Model):
        user = models.ForeignKey(User)
        #define general fields
    
    class Freelancer(models.Model):
        profile = models.ForeignKey(UserProfile)
        #freelancer specific  fields
    
        class Meta:
            db_table = 'freelancer'
    
    class Customers(models.Model):
        profile = models.ForeignKey(UserProfile)
        #customer specific fields 
    
       class Meta:
            db_table = 'customer'
    

    You can then have as many Users as you want from the UserProfile.

提交回复
热议问题