def create_customer(request, pk=None): if request.method == 'GET': form = CustomerForm(request.POST or None) if pk is not None: instance = Contact.objects.get(pk=pk) form = CustomerForm(request.POST or None, initial={ 'name': instance.name, 'email': instance.email, 'phone_number': instance.phone_number, 'dog_name': instance.dog_name, 'service_type': instance.service_type }) elif request.method == 'POST': form = CustomerForm(request.POST or None) if form.is_valid(): form.save() messages.success(request, 'Klient został pomyślnie utworzony') return HttpResponseRedirect(reverse('backoffice_customer_list')) return render(request, 'backoffice/customer/create.html', {'form': form})