Skip to content

Commit

Permalink
37 - Class Based Views - DetailView
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Jul 14, 2018
1 parent e71c6bc commit aff254f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/blog/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.urls import path
from .views import (
ArticleListView
ArticleDetailView,
ArticleListView

)

app_name = 'articles'
urlpatterns = [
path('', ArticleListView.as_view(), name='article-list'),
#path('create/', view_name, name='article-create'),
#path('<int:id>/', view_name, name='article-detail'),
path('<int:id>/', ArticleDetailView.as_view(), name='article-detail'),
#path('<int:id>/update/', view_name, name='article-update'),
#path('<int:id>/delete/', view_name, name='article-delete'),
]
16 changes: 14 additions & 2 deletions src/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404

from django.views.generic import (
CreateView,
Expand All @@ -14,4 +14,16 @@

class ArticleListView(ListView):
template_name = 'articles/article_list.html'
queryset = Article.objects.all() # <blog>/<modelname>_list.html
queryset = Article.objects.all() # <blog>/<modelname>_list.html


class ArticleDetailView(DetailView):
template_name = 'articles/article_detail.html'
queryset = Article.objects.filter(id__gt=1)

# def get_object(self):
# id_ = self.kwargs.get("id")
# return get_object_or_404(Article, id=id_)



0 comments on commit aff254f

Please sign in to comment.