Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def prefetched_related(instance, name, default=None):
  2. """
  3. Attempts to find and return prefetched data on a model.
  4.  
  5. Usage:
  6. values, prefetched = prefetched_related(instance, 'name')
  7.  
  8. values : A list of prefetched values for the field.
  9. prefetched : True if the requested field was prefetched on the instance.
  10. """
  11. if hasattr(instance, '_prefetched_objects_cache'):
  12.  
  13. # Use the prefetched values only if the requested field was prefetched.
  14. if name in instance._prefetched_objects_cache:
  15. return instance._prefetched_objects_cache[name], True
  16.  
  17. return default, False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement