Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # If no query is entered, will bring you to blank search screen. Otherwise will pull results from keyword, and results from content and display in search.html
- @login_required(login_url='/auth/login/')
- def search(request):
- query = request.GET.get('q')
- results = []
- notecard_list = []
- results = Notecard.objects.filter(section__semester__user=request.user)
- if query:
- results = results.filter(Q(notecard_body__icontains=query)|Q(notecard_name__icontains=query))
- paginator = Paginator(results, 6)
- try:
- page = int(request.GET.get('page', '1'))
- except ValueError:
- page = 1
- try:
- notecard_list = paginator.page(page)
- except (EmptyPage, InvalidPage):
- notecard_list = paginator.page(paginator.num_pages)
- return list_detail.object_list(
- request,
- queryset = Notecard.objects.filter(section__semester__user=request.user),
- template_name = "notecards/search.html",
- template_object_name = "results",
- extra_context = {"results": results, "notecard_list": notecard_list,},
- )
Advertisement
Add Comment
Please, Sign In to add comment