Django学习(第四天:ORM&Model)

2017-08-05  本文已影响585人  罗罗攀

ORM,是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换。

Model

from django.utils import timezone

# Create your models here.

class UserInfo(models.Model):
    js_id = models.CharField(max_length=50,verbose_name=u'简书id')
    wx_id = models.CharField(max_length=20,verbose_name=u'微信id')
    nick_name = models.CharField(max_length=20, verbose_name=u"群昵称")
    gender = models.CharField(max_length=1, verbose_name=u"性别")
    age = models.IntegerField(verbose_name=u"年龄")
    major = models.CharField(max_length=30, verbose_name=u"专业")
    job = models.CharField(max_length=20, verbose_name=u"职业")
    hobby = models.CharField(max_length=50, verbose_name=u"兴趣爱好")
    level = models.CharField(max_length=5, verbose_name=u"Python基础")
    is_new = models.CharField(max_length=1, verbose_name=u"有无其他编程语言基础")
    learn_time = models.CharField(max_length=10, verbose_name=u"学习时间")
    has_book = models.CharField(max_length=100, verbose_name=u"有无Python相关书籍")
    creat_time = models.DateTimeField(default=timezone.now, verbose_name=u"创建时间")

settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'helloweb',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': 'localhost',
        'PORT': '3306'
    }
}

migrate和makemigrations

上一篇下一篇

猜你喜欢

热点阅读