from django.shortcuts import render, get_object_or_404

from django.http import  HttpResponseRedirect
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.core.urlresolvers import reverse


from .models import Question, Choice

from django.utils import timezone


# Create your views here.

class IndexView(ListView):
	template_name = 'polls/index.html'
	context_object_name = 'latest_question_list'

	def get_queryset(self):
		"""Return the last five published questions."""
		return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]

class DetailView(DetailView):
	model = Question
	template_name = 'polls/detail.html'

	return Question.objects.filter(pub_date__lte=timezone.now())

def vote(request, question_id):
	question = get_object_or_404(Question, pk=question_id)
	try:
		selected_choice = question.choice_set.get(pk=request.POST['choice'])
	except (KeyError, Choice.DoesNotExist):
		# Redisplay voting form
		return render(request, 'polls/detail.html', {
			'question': question,
			'error_message': "You didn't select a choice.",
			})
	else:
		selected_choice.votes += 1
		selected_choice.save()
		# Always return HTTPResponseRedirect after
		# successfully dealing with POST data to 
		# prevent data from being posted twice if 
		# a user hits the back button
		return HttpResponseRedirect(reverse('polls:results', args = (question.id,)))
		
class ResultsView(DetailView):
	model = Question
	template_name = 'polls/results.html'
6af204ed92de6f5ce4b6b394ca2c3a203fb225b3
<mask token>


class DetailView(DetailView):
    model = Question
    template_name = 'polls/detail.html'
    return Question.objects.filter(pub_date__lte=timezone.now())


<mask token>


class ResultsView(DetailView):
    model = Question
    template_name = 'polls/results.html'

<mask token>


class IndexView(ListView):
    <mask token>
    <mask token>

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by(
            '-pub_date')[:5]


class DetailView(DetailView):
    model = Question
    template_name = 'polls/detail.html'
    return Question.objects.filter(pub_date__lte=timezone.now())


<mask token>


class ResultsView(DetailView):
    model = Question
    template_name = 'polls/results.html'

<mask token>


class IndexView(ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by(
            '-pub_date')[:5]


class DetailView(DetailView):
    model = Question
    template_name = 'polls/detail.html'
    return Question.objects.filter(pub_date__lte=timezone.now())


<mask token>


class ResultsView(DetailView):
    model = Question
    template_name = 'polls/results.html'

<mask token>


class IndexView(ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by(
            '-pub_date')[:5]


class DetailView(DetailView):
    model = Question
    template_name = 'polls/detail.html'
    return Question.objects.filter(pub_date__lte=timezone.now())


def vote(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    try:
        selected_choice = question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/detail.html', {'question': question,
            'error_message': "You didn't select a choice."})
    else:
        selected_choice.votes += 1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question
            .id,)))


class ResultsView(DetailView):
    model = Question
    template_name = 'polls/results.html'

from django.shortcuts import render, get_object_or_404

from django.http import  HttpResponseRedirect
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.core.urlresolvers import reverse


from .models import Question, Choice

from django.utils import timezone


# Create your views here.

class IndexView(ListView):
	template_name = 'polls/index.html'
	context_object_name = 'latest_question_list'

	def get_queryset(self):
		"""Return the last five published questions."""
		return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]

class DetailView(DetailView):
	model = Question
	template_name = 'polls/detail.html'

	return Question.objects.filter(pub_date__lte=timezone.now())

def vote(request, question_id):
	question = get_object_or_404(Question, pk=question_id)
	try:
		selected_choice = question.choice_set.get(pk=request.POST['choice'])
	except (KeyError, Choice.DoesNotExist):
		# Redisplay voting form
		return render(request, 'polls/detail.html', {
			'question': question,
			'error_message': "You didn't select a choice.",
			})
	else:
		selected_choice.votes += 1
		selected_choice.save()
		# Always return HTTPResponseRedirect after
		# successfully dealing with POST data to 
		# prevent data from being posted twice if 
		# a user hits the back button
		return HttpResponseRedirect(reverse('polls:results', args = (question.id,)))
		
class ResultsView(DetailView):
	model = Question
	template_name = 'polls/results.html'