employees = temployee.objects.all()
for employee in employees:
    employee.salary += 1000


from django.db.models import F


authors = Author.objects.all()
for author in authors:
    if ==


from django.db.models import F 
authors = Author.objects.filter(name=F("emial"))



books = Book.objects.filter(price__gte=100,rating__gte=9)


from django.db.models import Q
books = Book.objects.filter(Q(price__lte=10) | Q(rating__lte=9))

上面进行的是或运算,当然还可以进行其他的运算,比如有 & 和 ~ (非)等。我们可以参考下面的一些Q表达式的例如:

from django.db.models import Q
# 获取id等于3的图书
books = Book.objects.filter(Q(id=3))

# 获取id等于3,或者名字中包含文字“记”的图书
books = Book.objects.filter(Q(id=3) | Q(name__contains("记")))

# 获取价格大于100,并且书名中包含“记”的图书
books = Book.objects.filter(Q(price__gte=100) & Q(name__contains("记")))

# 获取书名包含“记”,但是id不等于3的图书
books = Book.objects.filter(Q(name__contains("记")) & ~Q(id=3))



  1. If some one desires to be updated with most up-to-date technologies therefore he must be visit this web page and be up to date everyday. Marjory Wainwright Varden

  2. I think that is among the such a lot vital information for me. Ardelle Bryce Toddie

  3. For most recent information you have to go to see web and on the web I found this web site as a most excellent web site for most recent updates. Liane Aldo Agathy

  4. Opportunities are now available in New Jersey. Get started today. Remy Cyrillus Darcee

  5. Good article! We will be linking to this particularly great content on our site. Keep up the great writing. Riane Pietrek Jegger

  6. Happy Faces We are up to standard with our products and services. We will meet your request and we hope that you leave us your testimony to encourage others. Vinnie Nickolas Tamara

  7. I have read so many articles about the blogger lovers however this paragraph is in fact a nice paragraph, keep it up. Tilly Haze Ori

  8. Pretty section of content. I just stumbled upon your website and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I will be subscribing to your feeds and even I achievement you access consistently fast. Sonni Reuben Alix

  9. Everyone loves it when people get together and share views. Great site, stick with it! Orelle Robin Gavin

  10. Thanks for fantastic info I was looking for this info for my mission. Mellisa Jan Hilaria

  11. Very good article. I am going through some of these issues as well.. Madelina Joel Sergias

  12. Popcorn Time does not smack you with annoying ads wuen streaming films or TV exhibits. Teriann Vinny Silvester

  13. Excellent site. A lot of helpful info here. I am sending it to several buddies ans additionally sharing in delicious.
    And obviously, thanks to your effort!


邮箱地址不会被公开。 必填项已用*标注