Django—好大夫医生数据管理

一、新建数据库

字符集:utf8 --UTF-8 Unicode
排序规则:utf8_general_ci
数据库名:Haodf_DOC

二、新建项目:Django

pip install django==1.9

#windows系统用exe安装
pip install mysql-python

三、Django app设计

xadmin——后台管理平台-操作数据中的医生数据
用户做权限限制,不可删除

四、配置model

/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'doc',
        'USER':'***',
        'PASSWORD':'*******',
        'HOST':'127.0.0.1'
    }
}

执行数据迁移
manage.py@_admin >makemigrations
manage.py@_admin >migrate

五、数据库设计

省份表

表名:省份
字段:省份id,省份名

地区表

表名:地区
字段:地区id,地区名,省份id

医院表

表名:医院
字段:医院id,医院名,医院等级,医院类型,地区id,

科室表

表名:科室
字段:科室id,科室名,医院id,

医生表

表名:医生
字段:医生id,医生姓名,科室id,职称,擅长,执业经历,感谢信数量,礼物数量,活跃热度,帮助患者数

六、建立app

新建app
manage.py@_admin > startapp doc

_建立model____/admin/models.py

# _*_ encoding:utf-8 _*_
from __future__ import unicode_literals

from django.db import models
from datetime import datetime
# Create your models here.

省份model

class Province(models.Model):
        pro = models.CharField(max_length=50,verbose_name=u'省份')

    class Meta:
        verbose_name = u'省份'
        verbose_name_plural = verbose_name

地区model

class Area(models.Model):
    pro = models.ForeignKey(Province,verbose_name=u'省份')
    area = models.CharField(max_length=50,verbose_name=u'地区')

    class Meta:
        verbose_name = u'地区'
        verbose_name_plural = verbose_name

医院model

class Hospital(models.Model):
    area = models.ForeignKey(Area,verbose_name=u'地区')
    hospital = models.CharField(max_length=100,verbose_name=u'医院名')
    level = models.CharField(max_length=20,verbose_name=u'医院等级')
    genre = models.CharField(max_length=20,verbose_name=u'医院类型')
    offce_url = models.URLField(max_length=100, verbose_name=u'医院网址')
    add_time = models.DateTimeField(default=datetime.now,verbose_name=u'变更时间')

    class Meta:
        verbose_name = u'医院'
        verbose_name_plural = verbose_name

科室model

class Office(models.Model):
    hospital = models.ForeignKey(Hospital, verbose_name=u'医院名')
    office = models.CharField(max_length=100,verbose_name=u'科室名')
    offce_url = models.URLField(max_length=100,verbose_name=u'科室网址')
    describe = models.TextField(verbose_name=u'科室介绍')
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u'变更时间')

    class Meta:
        verbose_name = u'科室'
        verbose_name_plural = verbose_name

医生model

class Doctor(models.Model):
    office = models.ForeignKey(Office, verbose_name=u'科室名')
    docname = models.CharField(max_length=50,verbose_name=u'医生姓名')
    title = models.CharField(max_length=100,verbose_name=u'职称')
    specialize = models.TextField(verbose_name=u'擅长')
    resume = models.TextField(verbose_name=u'执业经历')
    thanks = models.IntegerField(default=0, verbose_name=u'感谢信数')
    gifts = models.IntegerField(default=0, verbose_name=u'礼物数')
    hots = models.IntegerField(default=0,verbose_name=u'活跃热度')
    helps = models.IntegerField(default=0,verbose_name=u'帮助患者数')
    offce_url = models.URLField(max_length=100, verbose_name=u'医生网址')
    has_check = models.BooleanField(default=False,verbose_name=u'是否验证')
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u'变更时间')

    class Meta:
        verbose_name = u'医生'
        verbose_name_plural = verbose_name

再次执行数据迁移
manage.py@_admin >makemigrations
manage.py@_admin >migrate

配置地区时间
/settings.py

LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False

你可能感兴趣的:(Django—好大夫医生数据管理)