Hi all,

I'd like to propose adding a method to Model that can be used to fetch
a "fresh" version of a model object from the database. This is
something that I personally would often find useful. Usually this
happens when I'm testing some view code using the test client, and the
view is supposed to save some model changes into database. For
example:

client.post('some_url', {'id': obj.id, 'description': 'new'})
fresh_obj = ObjClass.objects.get(pk=obj.pk)
self.assertEqual('new', fresh_obj.description)

Now, I think that way of refreshing a model object is inelegant. What
I propose is a method that would be functionally identical to how a
fresh object is fetched above:

fresh_obj = obj.refetch()

This is a convenience method, but based on my own experience it would
be... well, convenient. I'd like to hear whether you think the
convenience would be worth extending the api. If you think it's worth
it, I'd be happy to write a patch.

--Jukka

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to