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())