Thursday, May 13, 2010

How to reload an object's member field?

I have a model Foo. If I've got a model instance foo, and I know that
foo.value may be changed after I got it.
How can I reload foo.value? For example, this way works:

foo = Foo.objects.get(foo.id)

Is this the only solution? In case that I'm in a member method of Foo.
It would looks like this:

def some_method_of_Foo(self, *args):
new_self = Foo.objects.get(self.id)
self.value = new_self.value
...

I think it's somewhat unclear. How can I do this better?

Thanks.


Ps.

The scenario is like this: I use a model Foo and a field Foo.state to
record states.
There is a daemon which do some operations related to Foo and check an
instance foo.state regularly.
The daemon would run or stop based on foo.state. So it needs to reload
foo.state.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate