Created
September 14, 2017 06:52
-
-
Save allieus/aa01c24d4796843a0bef8e21d89ca741 to your computer and use it in GitHub Desktop.
https://nomade.kr/vod/#comment-3516747121 질문에 대한 답변 코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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