Skip to content

Instantly share code, notes, and snippets.

@allieus
Created September 14, 2017 06:52
Show Gist options
  • Save allieus/aa01c24d4796843a0bef8e21d89ca741 to your computer and use it in GitHub Desktop.
Save allieus/aa01c24d4796843a0bef8e21d89ca741 to your computer and use it in GitHub Desktop.
https://nomade.kr/vod/#comment-3516747121 질문에 대한 답변 코드
from django.views.generic import ListView
from .models import Post
class PostListView(ListView):
model = Post
def get_queryset(self):
self.q = self.request.GET.get('q', '')
qs = super().get_queryset()
if self.q:
qs = qs.filter(title__icontains=self.q)
return qs
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['q'] = self.q
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment