from django.views.generic import ListView, DetailView

from .models import Post


class PostListView(ListView):
    context_object_name = 'posts'
    model = Post
    template_name = 'hermes/post_list.html'
    
    def get_queryset(self):
        return self.model.objects.order_by('created_on')


class CategoryPostListView(PostListView):
    def get_queryset(self):
        category_slug = self.kwargs.get('slug', '')
        return self.model.objects.in_category(category_slug)


class ArchivePostListView(PostListView):
    def get_queryset(self):
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)

        return self.model.objects.created_on(year=year, month=month, day=day)


class PostDetail(DetailView):
    context_object_name = 'post'
    model = Post
    template_name = "hermes/post_detail.html"

from django.views.generic import ListView, DetailView

from .models import Post


class PostListView(ListView):
    context_object_name = 'posts'
    model = Post
    template_name = 'hermes/post_list.html'
    
    def get_queryset(self):
        return self.model.objects.order_by('created_on')


class CategoryPostListView(PostListView):
    slug = None
    
    def get_queryset(self):
        category_slug = self.kwargs.get('slug', '')
        return self.model.objects.in_category(category_slug)


class ArchivePostListView(PostListView):
    def get_queryset(self):
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)

        return self.model.objects.created_on(year=year, month=month, day=day)


class PostDetail(DetailView):
    context_object_name = 'post'
    model = Post
    template_name = "hermes/post_detail.html"

Add slug variable to pass in the URL
Add slug variable to pass in the URL
  from django.views.generic import ListView, DetailView
  
  from .models import Post
  
  
  class PostListView(ListView):
      context_object_name = 'posts'
      model = Post
      template_name = 'hermes/post_list.html'
      
      def get_queryset(self):
          return self.model.objects.order_by('created_on')
  
  
  class CategoryPostListView(PostListView):
+     slug = None
+     
      def get_queryset(self):
          category_slug = self.kwargs.get('slug', '')
          return self.model.objects.in_category(category_slug)
  
  
  class ArchivePostListView(PostListView):
      def get_queryset(self):
          year = self.kwargs.get('year', None)
          month = self.kwargs.get('month', None)
          day = self.kwargs.get('day', None)
  
          return self.model.objects.created_on(year=year, month=month, day=day)
  
  
  class PostDetail(DetailView):
      context_object_name = 'post'
      model = Post
      template_name = "hermes/post_detail.html"
  
Add slug variable to pass in the URL
## Code Before:
from django.views.generic import ListView, DetailView

from .models import Post


class PostListView(ListView):
    context_object_name = 'posts'
    model = Post
    template_name = 'hermes/post_list.html'
    
    def get_queryset(self):
        return self.model.objects.order_by('created_on')


class CategoryPostListView(PostListView):
    def get_queryset(self):
        category_slug = self.kwargs.get('slug', '')
        return self.model.objects.in_category(category_slug)


class ArchivePostListView(PostListView):
    def get_queryset(self):
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)

        return self.model.objects.created_on(year=year, month=month, day=day)


class PostDetail(DetailView):
    context_object_name = 'post'
    model = Post
    template_name = "hermes/post_detail.html"

## Instruction:
Add slug variable to pass in the URL
## Code After:
from django.views.generic import ListView, DetailView

from .models import Post


class PostListView(ListView):
    context_object_name = 'posts'
    model = Post
    template_name = 'hermes/post_list.html'
    
    def get_queryset(self):
        return self.model.objects.order_by('created_on')


class CategoryPostListView(PostListView):
    slug = None
    
    def get_queryset(self):
        category_slug = self.kwargs.get('slug', '')
        return self.model.objects.in_category(category_slug)


class ArchivePostListView(PostListView):
    def get_queryset(self):
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)

        return self.model.objects.created_on(year=year, month=month, day=day)


class PostDetail(DetailView):
    context_object_name = 'post'
    model = Post
    template_name = "hermes/post_detail.html"
