Re: Records doesn't sometimes get upated

2009-09-22 Thread Daniel Roseman

On Sep 22, 9:48 am, Szymon  wrote:
> On 21 Wrz, 22:47, Javier Guerra  wrote:
>
> > only if you include it in the parameter list:
>
> Oh, yes. I forget about self in my example, but in function that makes
> problem there is of course self in parameter list.

I suspect the problem isn't quite what you think it is. It looks like
the new value of the object will always be saved to the database, and
that instance will carry the new value. However, Django model
instances are independent of the database and of other instances that
refer to the same database row. So, if you have another instance
somewhere else in your code with the same database id, it won't be
updated even if you save this one - you'll need to get it again from
the database,
--
DR.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Records doesn't sometimes get upated

2009-09-22 Thread Szymon

On 21 Wrz, 22:47, Javier Guerra  wrote:
> only if you include it in the parameter list:

Oh, yes. I forget about self in my example, but in function that makes
problem there is of course self in parameter list.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Records doesn't sometimes get upated

2009-09-21 Thread Javier Guerra

On Mon, Sep 21, 2009 at 3:29 PM, Szymon  wrote:
> Isn't "self" refers to existing object?

only if you include it in the parameter list:

class whatever:
  def method (self, moreparams...):
... use 'self' instance...

-- 
Javier

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Records doesn't sometimes get upated

2009-09-21 Thread Szymon

Yes.

self.bar += c
self.save()

Isn't "self" refers to existing object?

On 21 Wrz, 16:18, phoebebright  wrote:
> The code looks like it only handles the case of adding a new foo
> object but your comments refer to "old values".  Are you also
> expecting this to work for an update?
>
> On Sep 21, 7:35 am, Szymon  wrote:
>
>
>
> > Hello,
>
> > I have strange problem. I will give example. I have model:
>
> > class foo(models.Model)
> >  bar = models.IntegerField()
>
> > and method in it
>
> >  def add_bar(c):
> >   from something.models import bar_log
> >   b = bar_log(foo=self, cnt=c)
> >   b.save()
> >   self.bar += c
> >   self.save()
>
> > ... and now the problem. Sometimes "bar" in "foo" doesn't get updated.
> > There is record in bar_log, but "bar" in "foo" have old value. How can
> > I trace problem? There are no exceptions at all.
>
> > I'm using Django 1.1, Postgresql with psycopg2 as interface. There are
> > two parts of my application - web interface and daemonized part that
> > runs some background tasks every 5 seconds.
>
> > Best regards,
> > Szymon
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Records doesn't sometimes get upated

2009-09-21 Thread phoebebright

The code looks like it only handles the case of adding a new foo
object but your comments refer to "old values".  Are you also
expecting this to work for an update?



On Sep 21, 7:35 am, Szymon  wrote:
> Hello,
>
> I have strange problem. I will give example. I have model:
>
> class foo(models.Model)
>  bar = models.IntegerField()
>
> and method in it
>
>  def add_bar(c):
>   from something.models import bar_log
>   b = bar_log(foo=self, cnt=c)
>   b.save()
>   self.bar += c
>   self.save()
>
> ... and now the problem. Sometimes "bar" in "foo" doesn't get updated.
> There is record in bar_log, but "bar" in "foo" have old value. How can
> I trace problem? There are no exceptions at all.
>
> I'm using Django 1.1, Postgresql with psycopg2 as interface. There are
> two parts of my application - web interface and daemonized part that
> runs some background tasks every 5 seconds.
>
> Best regards,
> Szymon
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Records doesn't sometimes get upated

2009-09-21 Thread Szymon

Hello,

I have strange problem. I will give example. I have model:

class foo(models.Model)
 bar = models.IntegerField()

and method in it

 def add_bar(c):
  from something.models import bar_log
  b = bar_log(foo=self, cnt=c)
  b.save()
  self.bar += c
  self.save()

... and now the problem. Sometimes "bar" in "foo" doesn't get updated.
There is record in bar_log, but "bar" in "foo" have old value. How can
I trace problem? There are no exceptions at all.

I'm using Django 1.1, Postgresql with psycopg2 as interface. There are
two parts of my application - web interface and daemonized part that
runs some background tasks every 5 seconds.

Best regards,
Szymon
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---