from django.shortcuts import render
from django.http import HttpResponse
from django.http import Http404
from .forms import UserModelForm


from .models import Pet

def pet_submission(request):
    if request.method == 'POST':
        form = UserModelForm(request.POST)
        if form.is_valid():

            u = form.save()
            users = Pet.objects.all()

            return render(request, 'display.html', {'users': users})
    else:
        form_class = UserModelForm
        return render(request, 'userdetails.html', {
        'form': form_class,
    })

def home(request):
    pets = Pet.objects.all()
    return render(request, 'home.html',{'pets': pets})

def pet_detail(request, id):
    try:
        pet = Pet.objects.get(id = id)
    except Pet.DoesNotExist:
        raise Http404('Pet not found')
    return render(request,'pet_detail.html',{'pet': pet})

