title: How do I write a Django ORM query for the reverse relationship in a one-to-many relationship?
body: <p>I'm using Django and Python 3.7.  I have the following two models in my models.py file ...</p>
  
  <pre><code>class Article(models.Model):
      created_on = models.DateTimeField(default=datetime.now)
  ...
  
  
  class ArticleStat(models.Model):
      article = models.ForeignKey(Article, on_delete=models.CASCADE, )
      elapsed_time_in_seconds = models.IntegerField(default=0, null=False)
  </code></pre>
  
  <p>I would like to write a Django ORM query where I select articles have a stat that's at least 5 minutes (300 seconds) old.  However, I don't know how to reference the ArticleStat object from the Article object.  Unsurprisingly, this</p>
  
  <pre><code>Article.objects.filter(articlestat.elapsed_time_in_seconds.lte==300)
  </code></pre>
  
  <p>produces a </p>
  
  <pre><code>NameError: name 'articlestat' is not defined
  </code></pre>
  
  <p>error.</p>
  
  <p><b>Edit:</b> Per the answer, I changed my ArticleStat model to</p>
  
  <pre><code>class ArticleStat(models.Model):
      article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='articlestats')
  </code></pre>
  
  <p>and then I ran the below query getting the error displayed</p>
  
  <pre><code>Article.objects.filter(articlestat_set__elapsed_time_in_seconds__lte==300)
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
  NameError: name 'articlestat_set__elapsed_time_in_seconds__lte' is not defined
  </code></pre>
  
  <p>Thought maybe there was an instance with plurality, so I tried an "s", but got an error ..</p>
  
  <pre><code>Article.objects.filter(articlestats_set__elapsed_time_in_seconds__lte==300)
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
  NameError: name 'articlestats_set__elapsed_time_in_seconds__lte' is not defined
  </code></pre>