Django __str__ function on many to one field is not returning the correct output
<p>I'm trying to define <code>__str__</code> function for models A and D for the purpose having human readable text in the admin site.  The problem is in model D's <code>__str__</code> function where <code>__str__</code> will return a many_to_one related field, it does not return the format as intended instead it just showa the default 'D object'.</p>

<pre><code>class A(models.Model):
    b = models.CharField(max_length = 32)
    c = models.CharField(max_length = 32)

    def __str__(self):
        return '%s %s' % (self.b, self.c)

class D(models.Model):
    e = models.ForeignKey(A)

    def __str_(self):
        return '%s %s' % (self.e.b, self.e.c)
</code></pre>

<p>You've got a typo in your method name. You wrote <code>__str_()</code> when it should be <code>__str__()</code>. So when you're calling <code>str()</code> on your model, it's calling the inherited <code>__str__()</code> method from the parent class.</p>

python django django-admin