Re: proposal: get_or_none QuerySet method

2007-03-10 Thread Malcolm Tredinnick
On Sat, 2007-03-10 at 15:54 +, whiteinge wrote: > If someone has a moment I would appreciate hearing a status update for > this ticket--it reports ready for checkin, will it still be included > in Django? > > I tested the patch and it works as advertised, also the docs are well > written. Thi

Re: proposal: get_or_none QuerySet method

2007-03-10 Thread whiteinge
If someone has a moment I would appreciate hearing a status update for this ticket--it reports ready for checkin, will it still be included in Django? I tested the patch and it works as advertised, also the docs are well written. This is functionality I'm looking forward to.

Re: proposal: get_or_none QuerySet method

2007-01-14 Thread Gary Wilson
On Dec 24 2006, 9:35 pm, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote: On 12/24/06 4:50 PM, Gary Wilson wrote: >> I have created a ticket for this too and have attached some code: >>http://code.djangoproject.com/ticket/3182 > Documentation and tests attached too now.Hm - I get a whole bunch of

Re: proposal: get_or_none QuerySet method

2007-01-03 Thread Waylan Limberg
On 1/3/07, Gary Wilson <[EMAIL PROTECTED]> wrote: Ok, after getting sidetracked by update() and update_or_create(), back to the topic of the OP. Here are some options: 1) Add a get_or_none() method that returns None if object does not exist. 2) Add a get_or_default() method that accepts a "

Re: proposal: get_or_none QuerySet method

2007-01-03 Thread Gary Wilson
Ok, after getting sidetracked by update() and update_or_create(), back to the topic of the OP. Here are some options: 1) Add a get_or_none() method that returns None if object does not exist. 2) Add a get_or_default() method that accepts a "default" keyword argument, the value of which gets r

Re: proposal: get_or_none QuerySet method

2006-12-25 Thread Gary Wilson
Gary Wilson wrote: Jacob Kaplan-Moss wrote: > On 12/24/06 11:15 PM, Gary Wilson wrote: > > Well, the two tickets are different functionality. I could create a > > single patch for both, the only thing was that in the patch for #3180 I > > added an "Updating objects" to the db api documentation,

Re: proposal: get_or_none QuerySet method

2006-12-24 Thread Gary Wilson
Jacob Kaplan-Moss wrote: On 12/24/06 11:15 PM, Gary Wilson wrote: > Well, the two tickets are different functionality. I could create a > single patch for both, the only thing was that in the patch for #3180 I > added an "Updating objects" to the db api documentation, but then > realized that i

Re: proposal: get_or_none QuerySet method

2006-12-24 Thread Jacob Kaplan-Moss
On 12/24/06 11:15 PM, Gary Wilson wrote: Well, the two tickets are different functionality. I could create a single patch for both, the only thing was that in the patch for #3180 I added an "Updating objects" to the db api documentation, but then realized that it should probably be integrated i

Re: proposal: get_or_none QuerySet method

2006-12-24 Thread Gary Wilson
Jacob Kaplan-Moss wrote: Hm - I get a whole bunch of failures when I apply the patch. Looking closer, you say it depends on an ``update()`` patch in #3181, but I don't see any such patch attached to #3181. Sorry about that, it should be #3180. Can you update #3182 to include this other patc

Re: proposal: get_or_none QuerySet method

2006-12-24 Thread Jacob Kaplan-Moss
On 12/24/06 4:50 PM, Gary Wilson wrote: I have created a ticket for this too and have attached some code: http://code.djangoproject.com/ticket/3182 Documentation and tests attached too now. Hm - I get a whole bunch of failures when I apply the patch. Looking closer, you say it depends on

Re: proposal: get_or_none QuerySet method

2006-12-24 Thread Gary Wilson
Gary Wilson wrote: I have created a ticket for this too and have attached some code: http://code.djangoproject.com/ticket/3182 Documentation and tests attached too now. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google G

Re: proposal: get_or_none QuerySet method

2006-12-21 Thread Gary Wilson
Joseph Perla wrote: Also, here's the pseudo-ish code for it: def update_or_create( --same arguments as get_or_create()-- ): object, created = Class.objects.get_or_create( --args above-- ) if not created: object.__dict__.update(defaults) object.save() return ob

Re: proposal: get_or_none QuerySet method

2006-12-21 Thread Gary Wilson
Joseph Perla wrote: There should also be an update_or_create() function. I often find myself get_or_creating, then updating the object's dict if it wasnt just created, then saving. This can easily be expressed more clearly in one line with this function. This gave me the idea of an update()

Re: proposal: get_or_none QuerySet method

2006-12-20 Thread Joseph Perla
Also, here's the pseudo-ish code for it: def update_or_create( --same arguments as get_or_create()-- ): object, created = Class.objects.get_or_create( --args above-- ) if not created: object.__dict__.update(defaults) object.save() return object Well, Class is self o

Re: proposal: get_or_none QuerySet method

2006-12-20 Thread Brantley Harris
On 12/18/06, Gary Wilson <[EMAIL PROTECTED]> wrote: What do you think about adding a get_or_none QuerySet method? +1 On 12/20/06, Joseph Perla <[EMAIL PROTECTED]> wrote: There should also be an update_or_create() function. +1 --~--~-~--~~~---~--~~ You recei

Re: proposal: get_or_none QuerySet method

2006-12-20 Thread Joseph Perla
There should also be an update_or_create() function. I often find myself get_or_creating, then updating the object's dict if it wasnt just created, then saving. This can easily be expressed more clearly in one line with this function. j On 12/20/06, Gary Wilson <[EMAIL PROTECTED]> wrote: Smi

Re: proposal: get_or_none QuerySet method

2006-12-20 Thread Gary Wilson
SmileyChris wrote: On Dec 19, 11:08 am, "Waylan Limberg" <[EMAIL PROTECTED]> wrote: > something like this: > > user = User.objects.get(pk=user_id, default=None) Except this would break (or at least limit the functionality of) objects which use "default" as a field name. Of course, this didn't

Re: proposal: get_or_none QuerySet method

2006-12-18 Thread Waylan Limberg
Nice job Honza. I was about to suggest just about the same, but hesitated because of the *args and **kwargs. I just wasn't sure why that made me hesitate. On 12/18/06, SmileyChris <[EMAIL PROTECTED]> wrote: > > On Dec 19, 11:08 am, "Waylan Limberg" <[EMAIL PROTECTED]> wrote: > > something like th

Re: proposal: get_or_none QuerySet method

2006-12-18 Thread SmileyChris
On Dec 19, 11:08 am, "Waylan Limberg" <[EMAIL PROTECTED]> wrote: > something like this: > > user = User.objects.get(pk=user_id, default=None) Except this would break (or at least limit the functionality of) objects which use "default" as a field name. --~--~-~--~~~--

Re: proposal: get_or_none QuerySet method

2006-12-18 Thread Honza Král
On 12/18/06, Waylan Limberg <[EMAIL PROTECTED]> wrote: > > On 12/18/06, Gary Wilson <[EMAIL PROTECTED]> wrote: > > > > I often find myself writing code like: > > > > try: > > user = User.objects.get(pk=user_id) > > except User.DoesNotExist: > > user = None > > > > What do you think about ad

Re: proposal: get_or_none QuerySet method

2006-12-18 Thread Waylan Limberg
On 12/18/06, Gary Wilson <[EMAIL PROTECTED]> wrote: > > I often find myself writing code like: > > try: > user = User.objects.get(pk=user_id) > except User.DoesNotExist: > user = None > > What do you think about adding a get_or_none QuerySet method? > > def get_or_none(self, **kwargs): >

proposal: get_or_none QuerySet method

2006-12-18 Thread Gary Wilson
I often find myself writing code like: try: user = User.objects.get(pk=user_id) except User.DoesNotExist: user = None What do you think about adding a get_or_none QuerySet method? def get_or_none(self, **kwargs): try: return self.get(**kwargs) except self.model.DoesNotEx