标签:ted spl pen alt register strong ima return .text
通过OEM技术,model层负责定义模型类,实际对应定义在数据库中的表,然后通过迁移数据库来进行持久化保存
随后通过向admin层注册模型,来达到界面化DM的效果
model层定义的类,一般用来被view层引用,来进行数据库的增删改查
百度百科 - ORM
https://baike.baidu.com/item/ORM/3583252?fr=aladdin
在learning_log/learninglogs/models.py中新建一个class(Topic-主题模型类),保存
from django.db import models # Create your models here. ‘‘‘ Django中模型类的属性types与外键等约束定义 https://docs.djangoproject.com/en/2.0/ref/models/fields/#field-types https://docs.djangoproject.com/en/2.0/ref/models/fields/#module-django.db.models.fields.related Django model中的 class Meta 详解 http://www.cnblogs.com/tongchengbin/p/7670927.html ‘‘‘ class Topic(models.Model): """用户学习的主题""" text = models.CharField(max_length=200) date_added = models.DateTimeField(auto_now_add=True) def __str__(self): """返回模型的字符串表示,admin页面上的显示与django中的查找""" return self.text class Entry(models.Model): """学到的有关某个主题的具体知识""" topic = models.ForeignKey(Topic, on_delete=models.CASCADE) text = models.TextField() date_added = models.DateTimeField(auto_now_add=True) class Meta: verbose_name_plural = ‘entries‘ def __str__(self): """返回模型的字符串表示,admin页面上的显示与django中的查找""" return self.text[:50] + "..." if len(self.text)>=50 else self.text
Django中模型类的属性types与外键等约束定义
https://docs.djangoproject.com/en/2.0/ref/models/fields/#field-types
Django model中的 class Meta 详解
http://www.cnblogs.com/tongchengbin/p/7670927.html
https://docs.djangoproject.com/en/2.0/ref/models/options/
python manage.py makemigrations learning_logs
python manage.py migrate
from django.contrib import admin # Register your models here. from learning_logs.models import Topic admin.site.register(Topic)
界面化:django-admin层
django-shell:django-view层
CharField类型属性在界面化上的显示
ForeignKeyField && TextField类型属性在界面化上的显示
标签:ted spl pen alt register strong ima return .text
原文地址:https://www.cnblogs.com/yc913344706/p/9165337.html