Re: Only save if changed?

2007-08-04 Thread Forest Bond
On Sat, Aug 04, 2007 at 12:09:07PM +0200, Michael Elsdoerfer wrote:
> 
> > def save(self):
> > if self.id is not None:
> > old_self = self.__class__.get(id = self.id)
> > if self.id is None or (old_self.city != self.city) or (
> >   old_self.state != self.state):
> > self.geocode = self.get_geocode()
> > super(SiteUser, self).save()
> 
> You can also monitor attribute changes via __setattr__, which will save you
> an additional query. That worked fine for me so far, although I am not 100%
> if there might not be some edge cases that could cause problems.

I can't think of any problems with that sort of approach, excluding the usual
problem of the database changing underneath you.  Didn't think of it, but it's a
good idea.

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net


signature.asc
Description: Digital signature


RE: Only save if changed?

2007-08-04 Thread Michael Elsdoerfer

> def save(self):
> if self.id is not None:
> old_self = self.__class__.get(id = self.id)
> if self.id is None or (old_self.city != self.city) or (
>   old_self.state != self.state):
> self.geocode = self.get_geocode()
> super(SiteUser, self).save()

You can also monitor attribute changes via __setattr__, which will save you
an additional query. That worked fine for me so far, although I am not 100%
if there might not be some edge cases that could cause problems.

Michael


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Only save if changed?

2007-08-03 Thread Forest Bond
On Fri, Aug 03, 2007 at 08:57:10PM -, [EMAIL PROTECTED] wrote:
> For anyone trying this, I had to make it
> old_self = self.__class__.objects.get(id = self.id)
> instead of
> old_self = self.__class__.get(id = self.id)

Right, that's what I meant :)

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net



signature.asc
Description: Digital signature


Re: Only save if changed?

2007-08-03 Thread [EMAIL PROTECTED]

On Aug 3, 3:44 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Thanks!
>
> On Aug 3, 3:04 pm, Forest Bond <[EMAIL PROTECTED]> wrote:
>
> > On Fri, Aug 03, 2007 at 07:37:17PM -, [EMAIL PROTECTED] wrote:
>
> > > In my site_users model (which extends auth user), I've got:
>
> > >  def save(self):
> > > self.geocode = self.get_geocode()
> > > super(SiteUser, self).save() # Call the "real" save() method.
>
> > > get_geocode makes a call out to google's geocoding service, gives the
> > > city and state, and returns the geocode. Since there's a lot of
> > > activity on site_users, updating for board post counts and all sorts
> > > of other things, I don't want to call get_geocode unless city and
> > > state have actually changed.
>
> > def save(self):
> > if self.id is not None:
> > old_self = self.__class__.get(id = self.id)
> > if self.id is None or (old_self.city != self.city) or (
> >   old_self.state != self.state):
> > self.geocode = self.get_geocode()
> > super(SiteUser, self).save()
>
> > -Forest
> > --
> > Forest Bondhttp://www.alittletooquiet.net
>
> >  signature.asc
> > 1KDownload

For anyone trying this, I had to make it
old_self = self.__class__.objects.get(id = self.id)
instead of
old_self = self.__class__.get(id = self.id)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Only save if changed?

2007-08-03 Thread [EMAIL PROTECTED]

Thanks!

On Aug 3, 3:04 pm, Forest Bond <[EMAIL PROTECTED]> wrote:
> On Fri, Aug 03, 2007 at 07:37:17PM -, [EMAIL PROTECTED] wrote:
>
> > In my site_users model (which extends auth user), I've got:
>
> >  def save(self):
> > self.geocode = self.get_geocode()
> > super(SiteUser, self).save() # Call the "real" save() method.
>
> > get_geocode makes a call out to google's geocoding service, gives the
> > city and state, and returns the geocode. Since there's a lot of
> > activity on site_users, updating for board post counts and all sorts
> > of other things, I don't want to call get_geocode unless city and
> > state have actually changed.
>
> def save(self):
> if self.id is not None:
> old_self = self.__class__.get(id = self.id)
> if self.id is None or (old_self.city != self.city) or (
>   old_self.state != self.state):
> self.geocode = self.get_geocode()
> super(SiteUser, self).save()
>
> -Forest
> --
> Forest Bondhttp://www.alittletooquiet.net
>
>  signature.asc
> 1KDownload


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---



Re: Only save if changed?

2007-08-03 Thread Forest Bond
On Fri, Aug 03, 2007 at 07:37:17PM -, [EMAIL PROTECTED] wrote:
> 
> In my site_users model (which extends auth user), I've got:
> 
>  def save(self):
> self.geocode = self.get_geocode()
> super(SiteUser, self).save() # Call the "real" save() method.
> 
> get_geocode makes a call out to google's geocoding service, gives the
> city and state, and returns the geocode. Since there's a lot of
> activity on site_users, updating for board post counts and all sorts
> of other things, I don't want to call get_geocode unless city and
> state have actually changed.

def save(self):
if self.id is not None:
old_self = self.__class__.get(id = self.id)
if self.id is None or (old_self.city != self.city) or (
  old_self.state != self.state):
self.geocode = self.get_geocode()
super(SiteUser, self).save()

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net


signature.asc
Description: Digital signature


Only save if changed?

2007-08-03 Thread [EMAIL PROTECTED]

In my site_users model (which extends auth user), I've got:

 def save(self):
self.geocode = self.get_geocode()
super(SiteUser, self).save() # Call the "real" save() method.

get_geocode makes a call out to google's geocoding service, gives the
city and state, and returns the geocode. Since there's a lot of
activity on site_users, updating for board post counts and all sorts
of other things, I don't want to call get_geocode unless city and
state have actually changed.

Is there a way to check if they've changed. I know there's an
ifchanged filter for templates, but don't know about this.

Or should I move it to the update profile view, and only get geocode
when they actually update their profile?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~--~~~~--~~--~--~---