Learn Django

View Comm - Add to Account Detail

With the communications detail page working on it's own, we can now focus on integrating the communication records into the account detail page. To do this we need to update the account detail view so that it queries the related communications for the account. We also need to update the account detail template so that it renders the related communications records.

Step 1: Update the Account Detail View

Follow these steps to update the Account Detail view.

  1. Open /.../crmeasy/crmapp/accounts/views.py
  2. Update the account_detail() view with the following new lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from crmapp.communications.models import Communication

@login_required()
def account_detail(request, uuid):

    account = Account.objects.get(slug=slug)
    if account.owner != request.user:
            return HttpResponseForbidden()

    contacts = Contact.objects.filter(account=account)
    communications = Communication.objects.filter(
        account=account).order_by('-created_on')

    variables = {
        'account': account,
        'contacts': contacts,
        'communications': communications,
    }

    return render(request, 'accounts/account_detail.html', variables)

Step 2: Update the Account Detail Template

Follow these steps to update the Account Detail template.

  1. Open /.../crmeasy/crmapp/templates/accounts/account_detail.html in your IDE
  2. Add this code after the {# List Communications #} comment
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{# List Communications #}
<div id="co-container" class="ad-container">
    <div class="ad-headers">
        <h4 class="ad-mh m-none">Communications</h4>
    </div>
    <div id="co-body" class="ad-container">
        {# Communications Item Form #}
        {# List of Communications #}
        <ul id="co-list" class="strip-list col-md-12 p-none">
            {% for comm in communications %}
                {% include 'communications/comm_item_view.html' %}
            {% endfor %}
        </ul>
    </div>
</div>

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 "add the communication details to account details"

Track your progress with a free account