title: How do I define the __str__ method for a foreignkey field in Django?
body: <p>How do I define the <strong>str</strong> method for a foreignkey field in Django? The code below does not work,</p>
  
  <pre><code>class A(models.Model):
      name = models.ForeignKey('B')
  
  def __str__(self):
      return self.name
  </code></pre>