def create_customer(request, pk=None): form = CustomerForm() if request.method == 'GET': if pk is not None: instance = Contact.objects.get(pk=pk) initial = {'name': instance.name, 'email': instance.email, 'phone_number': instance.phone_number, 'dog_name': instance.dog_name, 'service_type': instance.service_type} form = CustomerForm(request.POST or None, initial=initial) if form.is_valid(): form.save() messages.success(request, 'Klient został pomyślnie utworzony') return HttpResponseRedirect(reverse('backoffice_customer_list')) 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})