python mysql命令集合

创建模型对象

# -*- coding:UTF-8 -*-
from django.db import models

class BookInfoManager(models.Manager):
    # def get_queryset(self):
    #     return super(BookInfoManager,self).get_queryset().filter(isDelete = False)
    def get_queryset(self):
        return super(BookInfoManager,self).get_queryset().filter(isDelete=False)
    def create(self,btitle,bpub_date):
        bookinfo = BookInfo()
        bookinfo.btitle = btitle
        bookinfo.bpub_date = bpub_date
        bookinfo.bread = 0
        bookinfo.bcommet = 0
        bookinfo.isDelete = False
        return bookinfo

class BookInfo(models.Model):
    btitle = models.CharField(max_length=20)
    bpub_date = models.DateTimeField()
    bread = models.IntegerField(default=0,null=True)
    bcommet = models.IntegerField(default=0,null=True)
    isDelete = models.BooleanField(default=False)

    books = BookInfoManager()

    class Meta():
        ordering = ['id']
        # db_table = ['bookinfo']
        # 定义数据表名称,推荐使用小写字母,数据表的默认名称 _


class HeroInfo(models.Model):
    hname = models.CharField(max_length=20)
    hgender = models.BooleanField(default=True)
    isDelete = models.BooleanField(default=False)
    hcontent = models.CharField(max_length=100,null=True)
    hbook = models.ForeignKey('BookInfo')

1、desc booktest_heroinfo

python mysql命令集合_第1张图片
image.png

2、插入数据

insert into booktest_bookinfo(btitle,bpub_date,bread,bcommet,isDelete) values
('射雕英雄传','1980-5-1',12,34,0),
('天龙八部','1986-7-24',36,40,0),
('笑傲江湖','1995-12-24',20,80,0),
('雪山飞狐','1987-11-11',58,24,0)

3、select * from booktest_bookinfo;

python mysql命令集合_第2张图片
image.png

4、select * from booktest_bookinfo inner join booktest_heroinfo on booktest_bookinfo.id = hbook_id;

python mysql命令集合_第3张图片
image.png

5、删除数据
delete from df_user_userinfo where uname = 'user01';

你可能感兴趣的:(python mysql命令集合)