title: django many to many get attributes from other object
body: <p>So I've been using django for a while now, and it's great. I've recently come across a little bit of a problem, and I'm sure there's a crappy way to get it to work, but what I've found with Django is that they've usually built in all sorts of mechanisms to do things for you. So what I'm not finding is this:</p>
  
  <p>Here are my models:</p>
  
  <pre><code>class LandmarkGroup(models.Model):
      Name = models.CharField(max_length=150)
      Description = models.CharField(max_length=300, blank=True)
      IsActive = models.BooleanField(default=True)
      landmarks = models.ManyToManyField('Landmark', blank=True, null=True)
  
      def __unicode__(self):
              return self.Name
  
  class Landmark(models.Model):
      Name = models.CharField(max_length=150)
      Description = models.CharField(max_length=300, blank=True)
      Polygon = models.PolygonField()
      IsActive = models.BooleanField(default=True)
      objects = models.GeoManager()
  
      def __unicode__(self):
              return self.Name
  </code></pre>
  
  <p>I also have another model 'Team' that has a ManyToMany with LandmarkGroup, but I'm not going to post it here. I have a view where I query for all the landmarks that have a landmarkgroup that has a team with the same team id as the one I passed in:</p>
  
  <pre><code>def mobile_startup(request):
  ...
      landmarkGroups = LandmarkGroup.objects.filter(team=device.team, IsActive=True)
      landmarks = Landmark.objects.filter(landmarkgroup__team=device.team, IsActive=True)
  ...
  return render_to_response('webservice/mobile_startup.html', {'landmarks': landmarks, 'landmarkGroups': landmarkGroups})
  </code></pre>
  
  <p>Everything works, the only problem I'm having is, I'm returning this all as JSON to the mobile app, and I want to provide the landmarkGroup id for the landmark, so in my template I've been trying to:</p>
  
  <pre><code>"landmarkGroup" : {{ landmark.landmarkgroup.id }} }
  </code></pre>
  
  <p>but that's not working. Does anyone know any way I can get the landmarkGroup ID for each landmark in my set? Do I need to extract it when I do the query? I know I can reference each landmarkGroup in the query because I can do 'landmarkgroup__team=device.team', but I need to able to reference this object in the template</p>