Opened 15 years ago

Closed 15 years ago

#12709 closed (duplicate)

Refetch method for getting a fresh model instance

Reported by: Jukka Välimaa Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: Keywords: refetch
Cc: Jukka Välimaa Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It is often useful to get a fresh instance of a model object, with data from db. A typical case is testing some view code using the test client, when 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)

This ticket proposes adding a method to Model that can be used to fetch a "fresh" version of a model object from the database. It is functionally the same as the use of objects.get in the example above, but more convenient and elegant.

fresh_obj = obj.refetch()

Change History (4)

comment:1 by Jukka Välimaa, 15 years ago

Cc: Jukka Välimaa added

comment:2 by Jukka Välimaa, 15 years ago

Version: 1.1

comment:3 by Karen Tracey, 15 years ago

Actually this was originally requested in #901.

comment:4 by Russell Keith-Magee, 15 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #901.

Note: See TracTickets for help on using tickets.
Back to Top