from django.shortcuts import render, redirect

from reportage.models import Article, Reportage, Photo


# Create your views here.
def article_liste(request, pk):
    try:
        listarticle = Article.objects.filter(annee=pk)
        listannee = Reportage.objects.all().order_by('-annee')
        annee = Reportage.objects.get(id=pk)
    except Reportage.DoesNotExist:
        return redirect('index')
    return render(request, 'article_liste.html', {'listarticle': listarticle, 'listannee': listannee, 'annee': annee})


def article_detail(request, pk):
    try:
        article = Article.objects.get(pk=pk)
        listphoto = Photo.objects.filter(article=article)
        listannee = Reportage.objects.all().order_by('-annee')
    except Article.DoesNotExist:
        return redirect('index')
    return render(request, 'article_detail.html', {'article': article, 'listphoto': listphoto, 'listannee': listannee})

