title: How to return an object along with a sub object in Django
body: <p>I am trying to display a camera object along with its most recent state. I am able to display camera and the most recent timestamp, but am struggling to access the corresponding state field.</p>
  
  <p>I have the following Django models.</p>
  
  <pre><code>class Camera(models.Model):
  
     name = models.CharField(max_length=32)
  
  
  class TimeStamp(models.Model):
  
     camera = models.ForeignKey(Camera, on_delete=models.CASCADE)
     state = models.BooleanField(default=False)
     timeStamp = models.DateTimeField(db_index=True, auto_now_add=True, blank=True)
  </code></pre>
  
  <p>And I have the following view.</p>
  
  <pre><code>def index(request):
    context = {
      'cameras': Camera.objects.all().annotate(latest_timestamp=Max('timestamp__timeStamp')),
      'functional': Camera.objects.annotate(latest_timestamp=Max('timestamp__timeStamp')).filter(latest_timestamp=F('timestamp__timeStamp'), timestamp__state=True),
      'faulty': Camera.objects.annotate(latest_timestamp=Max('timestamp__timeStamp')).filter(latest_timestamp=F('timestamp__timeStamp'), timestamp__state=False),
     }
  
  return render(request, 'index.html', context)
  </code></pre>
  
  <p>And in my index.html I have</p>
  
  <pre><code>&lt;table class="table table-hover"&gt;
  &lt;thead class="text-info"&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Current State&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
  &lt;/thead&gt;
      &lt;tbody&gt;
          {% for camera in cameras %}
              &lt;tr&gt;
                  &lt;td&gt;{{ camera.id }}&lt;/td&gt;
                  &lt;td&gt;{{ camera.name }}&lt;/td&gt;
                  &lt;td&gt;{{ camera.latest_timestamp }}&lt;/td&gt;
              &lt;/tr&gt;
          {% endfor %}
      &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p>Instead of camera.latest_timestamp, I would like to show the corresponding state field.</p>