Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: Accessing Many to Many object through another Many to Many relationship
    primarykey
    data
    text
    <p>I have simplified my models down a to make it clearer what I am trying to do.</p> <p>(models.py in app Teams)</p> <pre><code> from django.db import models from django.contrib.auth.models import User import datetime class Team(models.Model): users = models.ManyToManyField(User) team_title = models.CharField(max_length=200) team_description = models.CharField(max_length=200) def __unicode__(self): return self.team_title </code></pre> <p>(models.py in app Documents)</p> <pre><code>from django.db import models import datetime class Document(models.Model): teams = models.ManyToManyField("Teams.Team", blank=True) document_title = models.CharField(max_length=200) document_description = models.TextField() def __unicode__(self): return self.document_title </code></pre> <p>What I want to achieve is getting a list of users who have are associated with a Document by first getting all the teams associated with the document and then from this getting all the users associated with those teams.</p> <p>My attempts so far have gone something like this</p> <p>(view.py in app Documents)</p> <pre><code>from django.contrib.auth.models import User from Documents.models import * from Teams.models import * def docUsers(request, doc_id): current_document = Documents.objects.get(pk = doc_id) associated_users = current_document.teams.all().users .... </code></pre> <p><strong>Error:</strong> 'QuerySet' object has no attribute 'users'</p> <pre><code>associated_users = current_document.items.all().users.all() </code></pre> <p><strong>Error:</strong> 'QuerySet' object has no attribute 'users'</p> <pre><code>associated_users = current_document.items.users.all() </code></pre> <p><strong>Error:</strong> 'ManyRelatedManager' object has no attribute 'users'</p> <p>Am I going about this the wrong way? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload