zoukankan      html  css  js  c++  java
  • Python-S9-Day89_stark总结

    • 01 Stark总结

    • 02 ORM总结

    • 03 上节作业

    • 04 Stark组件之查看页面表头

    • 05 list_display_links

    • 06 stark组件之添加页面

    • 07 编辑删除页面

    01 Stark总结

    1.1 编写类starkConfig;

    1.2 注册类似于admin.site.register();

    1.3 设计URL;

    02 ORM总结

    2.1 基于双下划线的查询;

    models.py

    from django.db import models
    
    
    # Create your models here.
    
    class Author(models.Model):
        nid = models.AutoField(primary_key=True)
        name = models.CharField(max_length=32)
        age = models.IntegerField()
        # 与AuthorDetail建立一对一的关系;
        authorDetail = models.OneToOneField(to="AuthorDetail", on_delete=models.CASCADE)
    
        def __str__(self):
            return self.name
    
    
    class AuthorDetail(models.Model):
        nid = models.AutoField(primary_key=True)
        birthday = models.DateField()
        telephone = models.BigIntegerField()
        addr = models.CharField(max_length=64)
    
        def __str__(self):
            return self.telephone
    
    
    class Publish(models.Model):
        nid = models.AutoField(primary_key=True)
        name = models.CharField(max_length=32)
        city = models.CharField(max_length=32)
        email = models.EmailField()
    
        def __str__(self):
            return self.name
    
    
    class Book(models.Model):
        nid = models.AutoField(primary_key=True)
        title = models.CharField(max_length=32)
        publishDate = models.DateField()
        price = models.DecimalField(max_digits=5, decimal_places=2)
        # 与Publish表建立一对多的关系,外键字段在多的一方;
        publish = models.ForeignKey(to="Publish", to_field="nid", on_delete=models.CASCADE)
        # 与Author表建立多对多的关系,ManyToManyField可以建立在两个模型中的任意一个,自动创建第三张表;
        authors = models.ManyToManyField(to="Author")
    
        def __str__(self):
            return self.title

    views.py

    from django.shortcuts import render, HttpResponse
    
    # Create your views here.
    from .models import *
    
    
    def index(request):
        # ret1 = Publish.objects.filter(name="沙河出版社").values("book__title", "book__price")
        # print("ret1", ret1)
        # print("query", ret1.query)
    
        ret2 = Book.objects.filter(publish__name="沙河出版社").values("title", "price")
        print(ret2)
        print(ret2.query)
        return HttpResponse("ok")

    03 上节作业

    04 Stark组件之查看页面表头

    05 list_display_links

    06 stark组件之添加页面

    07 编辑删除页面

  • 相关阅读:
    error MSB6006: ”cmd.exe” exited with code 1
    OpenGL简介
    OSG例程(1) 交互(Pick)
    $err,hr
    [转载]操作数的寻址方式
    严重推荐的图形学讲义
    编译通过,运行时osgDB::ReadImageFile()出错 d和非d的lib
    空间变换的顺序SRT
    OSG例程(3) 利用更新回调制作路径动画
    Visitor模式的C++实现
  • 原文地址:https://www.cnblogs.com/tqtl911/p/9619023.html
Copyright © 2011-2022 走看看