Django - filter objects by number of related objects which meet a condition
<p>Given the following model:</p>

<pre><code>class EmailVerification(models.Model):
    user = models.ForeignKey(User, related_name='email_verifications')
    token = models.CharField(max_length=30)
    email = models.CharField(max_length=200)
    expiry = models.DateTimeField()
    verified = models.BooleanField(default=False)
</code></pre>

<p>I want to filter <code>User</code>s that have at least one verified email, so something like:</p>

<p><code>User.objects.filter(num_verified_emails__gt=0)</code> where:
<code>num_verified_emails = EmailVerification.objects.filter(user=user, verified=True).count()</code></p>

<p>Is there a way to accomplish this without using custom SQL?</p>

<p>Many thanks.</p>