Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 22, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/07a2c04f27fc974f0cf02b8f78b573d0 to your computer and use it in GitHub Desktop.
Save ychennay/07a2c04f27fc974f0cf02b8f78b573d0 to your computer and use it in GitHub Desktop.
data = instance.__dict__ # get the specific Student instance's symbol table
field_name = self.field.attname # pull out the field name (first name, in our case)
if data.get(field_name, self) is self:
# Let's see if the field is part of the parent chain. If so we
# might be able to reuse the already loaded value. Refs #18343.
val = self._check_parent_chain(instance) # check if this value is already pulled down from the db upstream
if val is None:
instance.refresh_from_db(fields=[field_name])
val = getattr(instance, field_name)
data[field_name] = val # set the student instance __dict__ key for future attribute lookups!
return data[field_name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment