from django.http import HttpResponse

def index(request):
    return HttpResponse('index')

def channel(request, name):
    return HttpResponse('channel: %s' % name)

def show(request, name, year, month, day):
    return HttpResponse('show: %s - %s/%s/%s' % (name, year, month, day))


from datetime import datetime

from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from annoying.decorators import render_to

from .models import Channel, Log

def index(request):
    return HttpResponse('index')

def channel_index(request, name):
    channel = get_object_or_404(Channel, name=name)
    return HttpResponse('channel: %s' % name)

@render_to('irclogview/show_log.html')
def show_log(request, name, year, month, day):
    channel = get_object_or_404(Channel, name=name)
    date = datetime(int(year), int(month), int(day)).date()

    log = get_object_or_404(Log, channel=channel, date=date)

    return {'log': log}


Add view to show log of a channel on a day
Add view to show log of a channel on a day

+ from datetime import datetime
+ 
  from django.http import HttpResponse
+ from django.shortcuts import get_object_or_404
+ 
+ from annoying.decorators import render_to
+ 
+ from .models import Channel, Log
  
  def index(request):
      return HttpResponse('index')
  
- def channel(request, name):
+ def channel_index(request, name):
+     channel = get_object_or_404(Channel, name=name)
      return HttpResponse('channel: %s' % name)
  
+ @render_to('irclogview/show_log.html')
- def show(request, name, year, month, day):
+ def show_log(request, name, year, month, day):
-     return HttpResponse('show: %s - %s/%s/%s' % (name, year, month, day))
+     channel = get_object_or_404(Channel, name=name)
+     date = datetime(int(year), int(month), int(day)).date()
+ 
+     log = get_object_or_404(Log, channel=channel, date=date)
+ 
+     return {'log': log}
  
  
Add view to show log of a channel on a day
## Code Before:
from django.http import HttpResponse

def index(request):
    return HttpResponse('index')

def channel(request, name):
    return HttpResponse('channel: %s' % name)

def show(request, name, year, month, day):
    return HttpResponse('show: %s - %s/%s/%s' % (name, year, month, day))


## Instruction:
Add view to show log of a channel on a day
## Code After:
from datetime import datetime

from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from annoying.decorators import render_to

from .models import Channel, Log

def index(request):
    return HttpResponse('index')

def channel_index(request, name):
    channel = get_object_or_404(Channel, name=name)
    return HttpResponse('channel: %s' % name)

@render_to('irclogview/show_log.html')
def show_log(request, name, year, month, day):
    channel = get_object_or_404(Channel, name=name)
    date = datetime(int(year), int(month), int(day)).date()

    log = get_object_or_404(Log, channel=channel, date=date)

    return {'log': log}

