zoukankan      html  css  js  c++  java
  • ORM实例

    from app01 import models
    
    《1》models.Book.objects.filter(id=2)
    《2》models.Book.objects.filter(title__contains="番茄")
    《3》models.Book.objects.filter(publish_day__year=2017)
    《4》models.Book.objects.filter(price__gt=10)
    《5》models.Book.objects.filter(price__gt=10).values("title","price")
    《6》models.Publisher.objects.filter(name__startswith="沙河")
    《7》 models.Author.objects.filter(name__contains="江")
    《8》obj = models.Book.objects.get(title="番茄物语").author_set.all()
    《9》obj = models.Book.objects.get(title="番茄物语").author_set.all().values()
    《10》models.Publisher.objects.get(name="沙河出版社").book_set.all().values('title','price')
    《11》models.Book.objects.filter(publisher__name="沙河出版社").values('title','price')
    

      

    from django.db.models import Avg,Max,Min
    
    《1》models.Book.objects.all().aggregate(Avg("price"))
    《2》models.Book.objects.all().aggregate(k1=Avg("price"))
    《3》models.Book.objects.all().aggregate(平均价格=Avg("price"))
    《4》models.Publisher.objects.get(name="沙河出版社").book_set.all().aggregate(Avg_price=Avg("price"))
    

      

    from django.db.models import Sum
    
    《1》models.Publisher.objects.get(name="沙河出版社").book_set.all().aggregate(sum_price=sum("price"))
    

      

  • 相关阅读:
    2019 SDN大作业
    个人作业——软件工程实践总结作业
    1.机器学习,从入门到放弃入门
    python25之进制转换
    python学习24之异常
    python学习23之标准库
    python学习22之函数式编程
    python学习21之高级特性
    python学习20之面向对象编程高级
    python学习19类5之多态与鸭子模型
  • 原文地址:https://www.cnblogs.com/mainstream/p/11013122.html
Copyright © 2011-2022 走看看