Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 21, 2020 03:39
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/b5a58acfc0edefae6570b51dd42f87f9 to your computer and use it in GitHub Desktop.
Save ychennay/b5a58acfc0edefae6570b51dd42f87f9 to your computer and use it in GitHub Desktop.
ForeignKeyDeferredAttribute example
class ForeignKeyDeferredAttribute(DeferredAttribute):
def __set__(self, instance, value):
if instance.__dict__.get(self.field.attname) != value and self.field.is_cached(instance):
self.field.delete_cached_value(instance)
instance.__dict__[self.field.attname] = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment