我有一个模型,可在views.py中呈现一个json文件:
def bill_sum(request):
data = Summary.objects.values('title','summary','summary_text')
return render(request,'billsummary.html',context={'data':data})
是否可以通过查找要从urls.py中传入的特定字符串来过滤summary_text对象查询?
类似于
from django.db.models import Q
Summary.objects.values('title;'summary',Q('summary_text'__contains=someword),...)
答案 0 :(得分:3)
确定有可能。尝试这样:
def some_view(request);
somewords = request.GET.get('somewords')
data = Summary.objects.filter(summary_text__icontains=somewords).values('title','summary','summary_text') # icontains has been used here instead of contains to ignore uppercase/lowercase issues