Opened 5 years ago

Closed 5 years ago

#12709 closed (duplicate)

Refetch method for getting a fresh model instance

Reported by: jukvalim Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: Keywords: refetch
Cc: jukvalim 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 5 years ago by jukvalim

  • Cc jukvalim added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by jukvalim

  • Version 1.1 deleted

comment:3 Changed 5 years ago by kmtracey

Actually this was originally requested in #901.

comment:4 Changed 5 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #901.

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