栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

初试django模型层

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

初试django模型层






from django.db import models

# Create your models here.

class Article(models.Model):
    #文章的唯一ID
    article_id = models.AutoField(primary_key = True)
    #文章标题
    title = models.TextField()
    #文章摘要
    brief_content = models.TextField()
    #文章内容
    content = models.TextField()
    #发布日期
    publish_date = models.DateField(auto_now = True)
    def __str__(self):
        return self.title
    #之后进行模型迁移,把模型保存到数据库里面
    #python manage.py makemigrations
    #python manage.py migrate
(mydjango) G:各种代码前端django_use_ide>python manage.py makemigrations
Migrations for 'blog':
  blogmigrations001_initial.py
    - Create model Article

(mydjango) G:各种代码前端django_use_ide>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, article, auth, blog, contenttypes, sessions
Running migrations:
  Applying blog.0001_initial... OK








将model在admin.py中注册一下

from django.contrib import admin
# Register your models here.
from .models import Article
# Register your models here.
admin.site.register(Article)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号