def post(self, request): if request.method == "POST": form = CompanyForm(request.POST) print(form.is_valid(), form.errors) if form.is_valid(): form = form.save(commit=False) form.owner = request.user form.logo = 'https://place-hold.it/130x80' form.save() return redirect('/mycompany/', pk=form.pk) else: form = CompanyForm() return render(request, 'company_create.html', {'form': form})
def post(self, request): current_user = request.user company = Company.objects.get(owner=current_user) form = CompanyForm(request.POST, instance=company) if form.is_valid(): form = form.save(commit=False) form.owner = current_user form.save() return redirect('/mycompany/') else: form = CompanyForm(instance=company) return render(request, 'company_edit.html', context={ 'form': form, 'company': company })