1. 程式人生 > >【django python】模型:查詢

【django python】模型:查詢

python manage.py shell

from blog.models import BlogArticles

查詢所有物件

BlogArticles.objects.all()

條件查詢

BlogArticles.objects.get(id=1)

BlogArticles.objects.get(title="第一篇部落格")

過濾

BlogArticles.objects.filter(username_endswith="部落格")

BlogArticles.objects.filter(username_startswith="第")

查詢排序

BlogArticles.objects.filter(username_startswith="第").order_by("-username")