title: Using UniqueConstraint to solve "get() returned more than one" error in Django admin
body: <p>I'm trying to access an (unmanaged) model via Django administration dashboard. The model doesn't have a primary key, but instead is unique across three fields.</p>
  
  <pre><code>class MyObjectView(models.Model):
      solution_id = models.IntegerField(blank=True, null=True)
      scenario_id = models.IntegerField(blank=True, null=True)
      object_id = models.CharField(max_length=256, blank=True, null=True)
      description= models.CharField(max_length=1000, blank=True, null=True)
      year_of_creation = models.DateField(blank=True, null=True)
  
      class Meta:
          managed = False  # Created from a view. Don't remove.
          db_table = 'myobject_view'
  </code></pre>
  
  <p>While I am able to access the list of all items in the admin dashboard, as soon as I try to view one specific item I get the error:</p>
  
  <blockquote>
    <p>get() returned more than one MyObjectView -- it returned 4!</p>
  </blockquote>
  
  <p>As per the <a href="https://docs.djangoproject.com/en/2.2/ref/models/constraints/#uniqueconstraint" rel="nofollow noreferrer">documentation</a>, I tried adding a <code>UniqueConstraint</code> in the <code>Meta</code> class, but the constraint doesn't seem to have any effect, and the error above persists:</p>
  
  <pre><code>    class Meta:
          managed = False  # Created from a view. Don't remove.
          db_table = 'myobject_view'
          constraints = [
              models.UniqueConstraint(fields=['solution_id', 'scenario_id', 'object_id '], name='unique_object'),
          ]
  </code></pre>
  
  <p>Is this the proper way to solve the <code>get() returned more than one</code> error? Should the constraint work even on an unmanaged model?</p>