Learn Django

Edit Account - Create/Update Templates

With the Account Detail functionality has been built we can now update the 'Add New Account' link on the Account List page. Follow these steps to do so.

Step 1: Update the Edit Link

Each account has an edit link. It already exists in the file but does not have an href value. Locate it now and update it as follows.

Open account_item_view.html. Locate the {# Account Edit Link #} comment and update this code beneath it.

1
2
3
4
5
{# Account Edit Link #}
<span>
    <a class="ad-control edit-account btn btn-link"
       href="{{ account.get_update_url }}">Edit</a>
</span>

Step 2: Update Form Action

The same form is used to create new accounts, as well as edit existing ones. The action attribute value needs to be updated based on what action is being performed. For example, if the user is creating a new account, the value should be '/acccount/new'. If the user is editing an account, the value should be /account//edit/'.

Open /.../crmeasy/crmapp/templates/accounts/account_item_form.html, locate the action= attribute of the form, and make it look like so:

1
2
3
4
<form id="gi-form"
      action="{% if account.uuid %}
      {{ account.get_update_url }}{% else %}{% url 'account_new' %}{% endif %}"
      method="post">

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 "updated templates to allow for editing accounts"

Track your progress with a free account