Code

Opened 4 years ago

Closed 4 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()

Attachments (0)

Change History (4)

comment:1 Changed 4 years ago by jukvalim

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

comment:2 Changed 4 years ago by jukvalim

  • Version 1.1 deleted

comment:3 Changed 4 years ago by kmtracey

Actually this was originally requested in #901.

comment:4 Changed 4 years ago by russellm

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

Duplicate of #901.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.