I have a page with a form I'd like to use both for editing and adding. I'd also like to change out the copy on this page based on whether the form is being used for editing or adding.
When being used for editing an existing object, I'm simply creating the form object with form = MyForm(instance=existingObject)
.
I tried using {% if form.instance %}
but this is true even for a form being used for adding (created with form = MyForm()
).
Is there some way to tell if a form has an existing object in it from within a template?
Instantly figured this out after submitting question:
{% if form.instance.id %}
will only be true for an 'edit' form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With