Am 25.07.2006 um 22:41 schrieb James Bennett: > > On 7/25/06, wnielson <[EMAIL PROTECTED]> wrote: >> if not self.genres.all(): >> try: >> genre=Genre.objects.get >> (name='default') #default genre >> except: >> genre=Genre(name='default') >> genre.save() >> self.genres.add(genre) #this >> doesn't appear to be called through > > I'm not 100% certain, but I *think* the problem is that > self.genres.all() will always evaluate True in this context, even when > there are no items in it -- you haven't done anything which will force > the QuerySet to be evaluated by checking the DB. > > What happens if you change it to 'if not self.genres.all().count()' ?
Wouldn't self.genres.all()[:1].count() save the database engine some work? Actually, an good exists() method for QuerySet would be handy! Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---