About filter
Model.objects.filter(pk=xxx, user=xxx)
1.
유저가 구독하고 있는 프로젝트를 확인
2.
그 프로젝트 안에 있는 게시글 가져오기
Articles.objects.filter(pk=xxx, user=xxx)
→ Articles.objects.filter(project__in=projects)
Field lookups
Double underscore
>SELECT WHERE project in
@method_decorator(login_required, 'get')
class SubscriptionListView(ListView):
model = Article
template_name = 'subscribeapp/list.html'
context_object_name = 'article_list'
paginate_by = 5
def get_queryset(self):
projects = Subscription.objects.filter(user=self.request.user).values_list('project')
article_list = Article.objects.filter(project__in=projects)
return article_list
Python
복사
{% extends 'base.html' %}
{% block content %}
<div>
{% include 'snippets/list_fragment.html' with article_list=article_list %}
</div>
{% endblock %}
Python
복사