Re: QuerySet.only()?

2009-03-30 Thread famousactress
Ah.. makes sense. I'd noticed that filter() returns QuerySet, but since QuerySet is essentially polymorphic as a list, I keep forgetting that's not what it is.. Obviously then, throwing an exception at filter () can't work, and throwing the exception upon iteration (even if possible) would be nast

Re: QuerySet.only()?

2009-03-30 Thread Malcolm Tredinnick
On Mon, 2009-03-30 at 15:53 -0700, famousactress wrote: > > Your permission is appreciated :) > > That said, wrapping up functions for utility is kinda the point of an > API so I figured I'd toss the question out to see whether or not > something that does this already exists or if enough folks

Re: QuerySet.only()?

2009-03-30 Thread famousactress
Your permission is appreciated :) That said, wrapping up functions for utility is kinda the point of an API so I figured I'd toss the question out to see whether or not something that does this already exists or if enough folks think it ought to to merit a patch. I'm curious what the motivation

Re: QuerySet.only()?

2009-03-30 Thread Alex Gaynor
On Mon, Mar 30, 2009 at 6:34 PM, famousactress wrote: > > Ooooh. Thanks, Karen.. This is exactly what I wanted. Although I still > wouldn't mind a function for when I'm not planning to immediately > create the object. Thanks for the tip! > > On Mar 30, 3:27 pm, Karen Tracey wrote: > > I think you

Re: QuerySet.only()?

2009-03-30 Thread famousactress
Ooooh. Thanks, Karen.. This is exactly what I wanted. Although I still wouldn't mind a function for when I'm not planning to immediately create the object. Thanks for the tip! On Mar 30, 3:27 pm, Karen Tracey wrote: > I think you missed get_or_create: > > http://docs.djangoproject.com/en/dev/ref

Re: QuerySet.only()?

2009-03-30 Thread Alex Gaynor
(name = facilityName).only() > > > > > if facility == None: > > >facility = Facility(name = facilityName) > > >facility.save() > > > > > return facility > > > > > ... In order to do this, I added the only() method to QuerySet: >

Re: QuerySet.only()?

2009-03-30 Thread Karen Tracey
On Mon, Mar 30, 2009 at 5:20 PM, famousactress wrote: > > Hello folks. I'm new to python, new to Django, but very old to ORMs > (via Java's Hibernate, mostly)... > > I naively assumed that QuerySet.filter() would return me None, if > there were no results. Instead it returns an empty list. That's

Re: QuerySet.only()?

2009-03-30 Thread famousactress
lityName).only() > > >  if facility == None: > >    facility = Facility(name = facilityName) > >    facility.save() > > >  return facility > > > ... In order to do this, I added the only() method to QuerySet: > > > def queryset_only(self): > >

Re: QuerySet.only()?

2009-03-30 Thread Dougal Matthews
ility.save() > >  return facility > > > ... In order to do this, I added the only() method to QuerySet: > > def queryset_only(self): >  i = len(self) >  if i == 0: >    return None >  elif i > 1: >    raise Exception("More than one element in this querySet

QuerySet.only()?

2009-03-30 Thread famousactress
_only(self): i = len(self) if i == 0: return None elif i > 1: raise Exception("More than one element in this querySet!!") else: return self[0] import new from django.db.models.query import QuerySet QuerySet.only = new.instancemethod(queryset_only,None,QuerySet) My q