Django:数据库查询写入

写入新的记录:

from movie.models import Movie
...
m = Movie()
m.XXX = XXX
m.save()

查询记录:

m = Movie.objects.get(name=i.name,site=i.site)
m = Movie.objects.get(name=i.name,site=i.site)

条件查询,QuerySet API reference

items = Movie.objects.filter()
items = Movie.objects.filter().order_by('name')

查询结果排序:

from django.db.models.functions import Coalesce

items = Question.objects.filter(market="sz").order_by(Coalesce('stock_code', 'answer_date').desc())

参考


微信公众号:我的网课 微信公众号:我的资产

results matching ""

    No results matching ""