Django Query SQL statement

Source: Internet
Author: User

Django Query SQL statement



#1 res=models. Book.objects.all () #Print (res) #<queryset [<book:book object>, <book:book object>, <book:book Object>, <book:b Ook object>, <book:book object>, <book:book object>]> #2 res=models. Book.objects.filter (price= ' 555 ') #Print (res) #<queryset [<book: King of Thieves;, <book: Doraemon >]> #3 res=models. Book.objects.get (nid=2) #print (res.price) #三月的狮子 #Res=models. Book.objects.get (nid=10) #Print (res) #只能用于一个对象的里面 #4 res=models. Book.objects.exclude (price= ' 555 ') #Print (res) #<queryset [<book: Hundred-Variable Sakura, <book: March Lion, <book: Mercury Navigator;, <book: Naruto >]> #5 res=models. Book.objects.values (' title ', ' Publishdate ') #Print (res) #<queryset [{' title ': ' Cherry blossom ', ' publishdate ': datetime.date (8, 8)}, {' title ': ' March lion ', ' Publishdate ': Datetime.date ()}, {' title ': ' Mercury Navigator ', ' publishdate ': Datetime.date (2004, 2, Max)}, {' title ': ' Naruto ', ' publishdate ': Datetime.date (1996, 1, 2)}, {' title ': ' King of Thieves ', ' publishdate ': Datetime.date (1995, 2, 2)}, {' title ': ' Doraemon ', ' publishdate ': Datetime.date (1969,,)}]> #6 res=models. Book.objects.values_list (' title ', ' Price ') #Print (res) #<queryset [(' Change Sakura ', decimal (' 155.00 ')), (' March lion ', Decimal (' 114.00 ')), (' Mercury Navigator ', Decimal (' 999.99 ')) , (' Naruto ', decimal (' 99.20 '), (' King of Thieves ', decimal (' 555.00 ')), (' Doraemon ', decimal (' 555.00 '))]> #7 Res=models. Book.objects.filter (price= ' 555 '). Distinct () #Print (res) #8 res=models. Book.objects.count () #Print (res) 6 #9 res=models. Book.objects.first () #Print (res) #百变小樱 #Ten res=models. Book.objects.exists () #Print (res) #True#################################################### #1 res=models. Book.objects.filter (price__gt=200) #Print (res) #<queryset [<book: Mercury Navigator;, <book: King of Thieves;, <book: Doraemon >]> # #2 res=models. Book.objects.filter (price__lte=555,price__gte=114) #Print (res) #<queryset [<book: Hundred Change Sakura, <book: March Lion, <book: the King of Thieves; <book: Doraemon >]> #3 res=models. Book.objects.filter (publishdate__year=2017) #Print (res) #<queryset [<book: March Lions >]> #4 res=models. Book.objects.filter (title__startswith= ' water ') #Print (res) #<queryset [<book: Mercury Navigator >]> #5 res=models. Book.objects.filter (title__contains= ' small ') #Print (res) #<queryset [<book: Hundred-variable Sakura >]>

Django Query SQL statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.