from django.shortcuts import render, redirect
from .models import Client
from .forms import ClientForm

def index(request):
    if request.method == 'POST':
        form = ClientForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('index')
    else:
        form = ClientForm()
    
    clients = Client.objects.all()
    return render(request, 'core/index.html', {'form': form, 'clients': clients})