Technically, it is possible to do this with the ORM.

```python
from datetime import datetime, timedelta
from django.db.models import Count, Q

new_users = User.objects.annotate(num_revisions=Count('created_revisions'))  # Or whatever the reverse relation is called.
new_users = new_users.filter(Q(num_revisions__lte=20) | Q(date_joined__gte=(datetime.now() - timedelta(days=7))))
new_user_ids = new_users.values_list('id')
```

This generates SQL like this:

```sql
SELECT `auth_user`.`id` FROM `auth_user` LEFT OUTER JOIN `wiki_revision`
ON (`auth_user`.`id` = `wiki_revision`.`creator_id`) GROUP BY
`auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`,
`auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`,
`auth_user`.`is_staff`, `auth_user`.`is_active`,
`auth_user`.`is_superuser`, `auth_user`.`last_login`,
`auth_user`.`date_joined` HAVING (COUNT(`wiki_revision`.`id`) <= 20  OR
`auth_user`.`date_joined` >= '2013-03-11 08:30:23' ) ORDER BY NULL;
```

Now, that's not necessarily super efficient, and raw SQL may very well perform better, I just wanted to point it out. (Though, this is _not fast_ anyway, and I think it's because...)

But I'm curious about two things:
1) This looks at all revisions ever created, that seems inefficient.
2) `created` in the `OR` clause refers to when the _revision_ was created, not when the user was. So, you're using the `newusers` flag to check to see if the user has revisions created in the past 7 days.

Can you add a comment or docstring to this `if` block explaining exactly what it's supposed to do? Whenever there's raw SQL in the code, we should explicitly state that in English.

I _suspect_ that you want to look at users who have fewer than 20 revisions or who were joined less than 7 days ago. I'd restrict the search to the users whose IDs are already in the `revisions` query, because I'd guess that most users have fewer than 20 revisions. And make sure you're looking at `auth_user.date_joined`, not `revision.created`, for user creation dates.