Pastebin
Paste #25065: No description
< previous paste - next paste>
Pasted by Anonymous Coward
# contact_edit.html {% extends 'crm/base.html' %} {% load django_bootstrap5 %} {% block content %} <h2>New contact</h2> <form method="POST" class="form"> {% csrf_token %} {% bootstrap_form form %} <button type="submit" class="save btn btn-secondary">Save</button> </form> <pre class="debug"> contact_edit.html </pre> {% endblock %} # contact_form.html {% extends 'crm/base.html' %} {% load django_bootstrap5 %} {% block content %} <h2>Edit contact</h2> <form method="POST" class="form"> {% csrf_token %} {% bootstrap_form form %} <button type="submit" class="save btn btn-secondary">Save</button> </form> <pre class="debug"> contact_form.html </pre> {% endblock %} # views.py new(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): contact = form.save(commit=False) contact.save() return redirect('contacts_view') else: form = ContactForm() return render(request, 'crm/contact_edit.html', {'form': form}) def contact_edit(request, pk): contact = get_object_or_404(Contact, pk=pk) if request.method == "POST": form = ContactForm(request.POST, instance=contact) if form.is_valid(): contact = form.save(commit=False) contact.save() return redirect('contacts_view') else: form = ContactForm(instance=contact) return render(request, 'crm/contact_edit.html', {'form': form}) class ContactEditView(UpdateView): model = Contact fields = ('name', 'customer', 'email', 'phone', 'title', 'notes', 'created_on', ) template_name_suffix = "_form"
New Paste
Go to most recent paste.