Learn Django

Edit Comm - Create/Update Templates

With the edit URL created, and the comm_cru() modified, we need to update two templates with updated targets.

Step 1: Update Form Post Action

The new comm form element previously had a blank action= attribute. That was ok because we were only adding new communications from the /comm/new/ URL. Now that the form is embedded, and that it can be used for either creating new communications or edit existing items, we need to update it. This code below will check to see if there is a comm object passed to the template; if there is then the /comm//edit/ URL will be set. If there isn't, then the /comm/new/ URL will be set.

Open /.../crmeasy/crmapp/templates/communications/comm_item_form.html and edit the form action attribute.

1
2
3
4
5
<form id="comm-form"
      {# POST Destination #}
      action="{% if comm.uuid %}
      {% url 'comm_update' comm.uuid %}{% else %}{% url 'comm_new'%}{% endif %}"
      method="post">

Step 2: Add the Edit URL

Update the edit communication URL to have the correct path. Open /.../crmeasy/crmapp/templates/communications/comm_item_view.html and update the following link.

1
2
3
{# Comm Edit URL #}
<a class="pen comm-control comm-edit" 
   href="{{ comm.get_update_url }}?account={{ account.id }}"></a>

Step 3: Commit Changes

Execute these commands to commit your changes in Git.

1
2
3
4
5
# add files
(venv)$ git add .

# commit files
(venv)$ git commit -m "created the edit communication template"

Track your progress with a free account