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
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
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
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
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
(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:
>
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
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):
> >
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
_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
10 matches
Mail list logo