【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")

猜你喜欢

转载自blog.csdn.net/qq1518572311/article/details/85094168
今日推荐