Django 모호한 질의

1346 단어 Django
모호한 조회:
def search(request):
    searchtype = request.POST.get("searchtype")
    keyword = request.POST.get("keyword")
    if searchtype == "all":
        #        ,             ,         ,        icontains contains,          ,       
        sciencenews = models.Sciencenews.objects.filter(Q(title__icontains=keyword)\
		|Q(content__icontains=keyword)|Q(author__icontains=keyword))
    elif searchtype == "author":
        #        
        sciencenews = models.Sciencenews.objects.filter(author__icontains=keyword)
    elif searchtype == "title":
        sciencenews = models.Sciencenews.objects.filter(title__icontains=keyword)
    elif searchtype == "content":
        sciencenews = models.Sciencenews.objects.filter(content__icontains=keyword)
	else:
		#      filter   and
		sciencenews = models.Sciencenews.objects.filter(author__icontains=keyword).\
			filter(title__icontains=keyword).filter(content__icontains=keyword)
		
    return render(request,"show/index.html",{"param":sciencenews,"searchtype":searchtype,"keyword":keyword})

참고 자료:
http://www.guojl.com/article/13/ 
https://www.douban.com/note/505215076/
http://xinleisky.blog.sohu.com/244421023.html
http://blog.sina.com.cn/s/blog_9e2e84050101j3ch.html

좋은 웹페이지 즐겨찾기