Opened 7 years ago

Closed 7 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: UI/UX:

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 Changed 7 years ago by Jukka Välimaa

Cc: Jukka Välimaa added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 7 years ago by Jukka Välimaa

Version: 1.1

comment:3 Changed 7 years ago by Karen Tracey

Actually this was originally requested in #901.

comment:4 Changed 7 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

Duplicate of #901.

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