Для цикла в представлениях django

def lead_unassigned(request): unassigned = Agent.objects.all() for i in range(0,len(unassigned)): team_unassigned=profile_candidate.objects.exclude(Reference_Mobile = (unassigned[i]))

return render(request, 'leads/lead_list_unassigned.html', 
{'team_unassigned':team_unassigned})
    

I am a beginner
This is my views.py code,
profile_candidate is my mode, refrence_mobile one of the field
Agent is my another model which contains the list of agents,
here my task is to display the list of profile_candidates in which the refernce_mobile is not matching with any of the agents available in agent table

i tried with the above but it is checking only the last agent in the Agent model.
it is not checking all the users available in the agent model.



 {% for i in team_unassigned %}
      <tr>
        <td>{{i.Name}}</td>
        <td>{{i.DOB}}</td>
        <td>{{i.highest_qualification}}</td>
        <td>{{i.online_exam_status}}</td>
        <td>
            <a class="btn btn-sm btn-success" href="{% url 'lead_detail' i.pk %}">View</a>
            
            <a class="btn btn-sm btn-success" href="{% url 'lead_update' i.pk %}">Update</a>
          </td>
        
      </tr>
        
    {% endfor %}
      
    </table>
    

this is my template displaying the list.

Can any one help me in achieving this,

При каждом выполнении цикла team_unassigned получает новое значение, как прокомментировал @dgw. Вы можете попробовать использовать метод in, например, так:

def lead_unassigned(request):
    unassigned = Agent.objects.all()
    team_unassigned=profile_candidate.objects.exclude(Reference_Mobile__in=(unassigned))

    return render(request, 'leads/lead_list_unassigned.html', 
    {'team_unassigned':team_unassigned})
Вернуться на верх