目录:
新建repository APP
为了将模型独立出来,新建repository APP
manage.py@autoserver > startapp repository
"C:\Program Files\JetBrains\PyCharm 2019.2\bin\runnerw64.exe" C:\Python36\python.exe "C:\Program Files\JetBrains\PyCharm 2019.2\helpers\pycharm\django_manage.py" startapp repository C:/Users/admin/Desktop/projects/autoserver
Tracking file by folder pattern: migrations
Following files were affected
C:\Users\admin\Desktop\projects\autoserver\repository\migrations\__init__.py
Process finished with exit code 0
cmdb表结构
models.py
from django.db import models
class UserProfile(models.Model):
"""
用户信息
"""
name = models.CharField(u'姓名', max_length=32)
email = models.EmailField(u'邮箱')
phone = models.CharField(u'座机', max_length=32)
mobile = models.CharField(u'手机', max_length=32)
password = models.CharField(u'密码', max_length=64)
class Meta:
verbose_name_plural = "用户表"
def __str__(self):
return self.name
class UserGroup(models.Model):
"""
用户组
"""
name = models.CharField(max_length=32, unique=True)
users = models.ManyToManyField('UserProfile')
class Meta:
verbose_name_plural = "用户组表"
def __str__(self):
return self.name
class BusinessUnit(models.Model):
"""
业务线
"""
name = models.CharField('业务线', max_length=64, unique=True)
contact = models.ForeignKey('UserGroup', verbose_name='业务联系人', related_name='c')
manager = models.ForeignKey('UserGroup', verbose_name='系统管理员', related_name='m')
class Meta:
verbose_name_plural = "业务线表"
def __str__(self):