On 4/12/06, Max Battcher <[EMAIL PROTECTED]> wrote:
> Oh, right.  You could do:
>
> tags = [tag for tag in Tag.objects.all() if tag.article_set.count() == 0]
>
> n queries for n tags, but it is "pretty" Python.  Doing db-cleanup
> shouldn't happen all that often, so you probably don't need the best
> performance, and I'd just stick with the list comprehension.
>
> Too bad there isn't some cool easy Python way to make a list
> comprehension/generators like that as Lazy as the Descriptors...

There is, but it's only in Python 2.4:

>>> g = (x**2 for x in range(10))
>>> g
<generator object at 0xb7d711cc>
>>> g.next()
0
>>> g.next()
1
>>> g.next()
4

Check out http://www.python.org/dev/peps/pep-0289/ (Generator Expressions)

--
Ian Clelland
<[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to