{% extends "base.html" %} {% block content %}

User Loans

Relationship: One user can loan multiple tablets (one-to-many). This page demonstrates the many-to-many relationship between users and tablets via the loans table.

{% for user_data in users_with_loans %} {% set user = user_data.user %} {% set loans = user_data.loans %} {% set active_loans = loans|selectattr('status', 'equalto', 'active')|list %} {% set returned_loans = loans|selectattr('status', 'equalto', 'returned')|list %}

{{ user.name }} ({{ user.identification }})

{{ active_loans|length }} active, {{ returned_loans|length }} past
{% if active_loans %}

Current Loans

{% for loan in active_loans %} {% endfor %}
Tablet Serial Number Loan Date Status
{{ loan.brand }} {{ loan.model }} {{ loan.serial_number }} {{ loan.loan_date }} {{ loan.status }}
{% endif %} {% if returned_loans %}

{% endif %} {% if not active_loans and not returned_loans %}

No loans recorded for this user.

{% endif %}
{% endfor %} {% if users_with_loans|length == 0 %}

No users found. Add users and loan tablets to see data here.

{% endif %}
{% endblock %}