我希望球员和教练在自己的额外字段中拥有自己的个人资料。 在安排时间时,参加特定训练的运动员应有一个具有各自专业的教练。那么如何创建带有额外字段的个人资料?
class UserType(models.Model):
user =models.OneToOneField(User, on_delete=models.CASCADE)
USER_TYPE = (
(1, 'Player'),
(2, 'Coach'),
)
user_type = models.IntegerField(choices=USER_TYPE)
class Schedule(models.Model):
Schedule_List = (
(1, '10:00 – 11:00'),
(2, '11:00 – 12:00'),
(3, '12:00 – 13:00'),
(4, '13:00 – 14:00'),
(5, '14:00 – 15:00'),
)
schedule = models.IntegerField(choices=Schedule_List, null=True)
user = models.ManyToManyField(User)
class Coach(models.Model):
usertype = models.OneToOneField(UserType, on_delete=models.CASCADE)
specialty = models.CharField(max_length=20)
picture = models.ImageField(upload_to = '', default = '')
#return the coach' name
def __str__(self):
return str(self.user)
class Player(models.Model):
usertype = models.OneToOneField(UserType, on_delete=models.CASCADE)
enrolled_training=models.CharField(max_lenght=20)
#return the players' name
def __str__(self):
return str(self.user)