Skip to content

Commit

Permalink
분류 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
정경업 committed Feb 4, 2015
1 parent 2f38bbd commit 713e03d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion blog/templates/_post.html
@@ -1,4 +1,9 @@
<article class="post">
<h1><a href="{% url 'detail' object.id %}">{{ object.title }}</a></h1>
<h1>
[{{ object.category.name }}]
<a href="{% url 'detail' object.id %}">
{{ object.title }}
</a>
</h1>
{{ object.content|linebreaksbr }}
</article>
6 changes: 5 additions & 1 deletion blog/templates/home.html
Expand Up @@ -3,7 +3,11 @@
<a href="{% url 'create' %}">글쓰기</a>
<ul class="category">
{% for category in categories %}
<li>{{ category.name }}</li>
<li>
<a href="{% url 'home' %}?category={{ category.id }}">
{{ category.name }}
</a>
</li>
{% endfor %}
</ul>
<div class="posts">
Expand Down
7 changes: 7 additions & 0 deletions blog/views.py
Expand Up @@ -14,6 +14,13 @@ def get_context_data(self, **kwargs):
context['categories'] = categories
return context

def get_queryset(self):
queryset = super(PostList, self).get_queryset()
category_id = self.request.GET.get('category')
if category_id:
queryset = queryset.filter(category=category_id)
return queryset


class PostDetail(DetailView):
model = Post
Expand Down

1 comment on commit 713e03d

@perhapsspy
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

브라우저 접속 : http://127.0.0.1:8000/?category=1

분류가 잘 작동하는지 확인합니다.

Please sign in to comment.