{
   "users": [

       {% for user in trainees %}
       {
           "id": "{{ user.id }}",
           "username": "{{ user.username }}",
           "first_name": "{{ user.first_name }}",
           "last_name": "{{ user.last_name }}",

           {% if user.photo %}
           "photo": "{{ user.photo.id }}",
           {% else %}
           "photo": null,
           {% endif %}

           "photos":  [
               {% for photo in user.photos.all %}
               {
             "id": "{{ photo.id }}",
             "hash": "{{ photo.hash }}",
             "img": "{{ photo.img.url }}",
               },
               {% endfor %}
           ],
           "groups":  [
               {% for group in user.mgroups.all %}
                "{{ group.name }}"{% if not forloop.last %},{% endif %}
               {% endfor %}
           ],
       },
       {% endfor %}

       {
           "id": "{{ trainer.id }}",
           "username": "{{ trainer.username }}",
           "first_name": "{{ trainer.first_name }}",
           "last_name": "{{ trainer.last_name }}",

           {% if user.photo %}
           "photo": "{{ user.photo.id }}",
           {% else %}
           "photo": null,
           {% endif %}

           "photos":  [
               {% for photo in user.photos.all %}
               {
             "id": "{{ photo.id }}",
             "hash": "{{ photo.hash }}",
             "img": "{{ photo.img.url }}",
               },
               {% endfor %}
           ],
           "groups":  [
               {% for group in trainer.mgroups.all %}
                "{{ group.name }}"{% if not forloop.last %},{% endif %}
               {% endfor %}
           ],
       },
   ]
}
