from django.shortcuts import render, redirect
from .models import Project
from .forms import ProjectForm

def index(request):
    projects = Project.objects.all().order_by('-start_date')
    return render(request, 'core/index.html', {'projects': projects})

def add_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('index')
    else:
        form = ProjectForm()
    return render(request, 'core/add_project.html', {'form': form})