title: Django: Iterate over QuerySet of a database view
body: <p>I have a Postgres database view which combines some data from other tables, and I have a Django model to reflect this view (simplified for this question):</p>
  
  <pre><code>class MyModel(models.Model):
      othermodel = models.ForeignKey(MyOtherModel, related_name='cached_points')
      num_points = models.IntegerField(default=0)
  
      class Meta(object):
          managed = False
  </code></pre>
  
  <p>Note the <em>managed = False</em> statement to make sure Django doesn't try to create or alter the table.</p>
  
  <p>All works fine with using this model, except for iterating over it. When I do, for example:</p>
  
  <pre><code>for item in MyModel.objects.all():
      ....
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <blockquote>
    <p>django.db.utils.ProgrammingError: column app_mymodel.id does not exist
    LINE 1: SELECT "app_mymodel"."id", "app_mymodel...</p>
  </blockquote>
  
  <p>I understand the error, as there is indeed no column 'id' in this (virtual) table, but the iterator uses it to iterate over the results.</p>
  
  <p>How can I iterate over this QuerySet without a primary key column?</p>
  
  <p>Thanks,
  Erik</p>