数据库设计
1.属性形同的归一张表
连表有性能消耗
(1):连表设计:
方式一:
class UserType(models.Model):
"""
用户类型表,个数经常变动
"""
title = models.CharField(max_length=32)
class UserInfo(models.Model):
"""
用户表:讲师和班主任
"""
username = models.CharField(max_length=32)
password = models.CharField(max_length=64)
email = models.CharField(max_length=32)
ut = models.ForeignKey(to="UserType")
方式二:
- choices
# class UserInfo(models.Model):
# """
# 用户表
# """
# username = models.CharField(max_length=32)
# password = models.CharField(max_length=64)
# email = models.CharField(max_length=32)
#
# user_type_choices = (
# (1, '班主任'),
# (2, '讲师'),
# )
#
# user_type_id = models.IntegerField(choices=user_type_choices)