Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prefetched_related(instance, name, default=None):
- """
- Attempts to find and return prefetched data on a model.
- Usage:
- values, prefetched = prefetched_related(instance, 'name')
- values : A list of prefetched values for the field.
- prefetched : True if the requested field was prefetched on the instance.
- """
- if hasattr(instance, '_prefetched_objects_cache'):
- # Use the prefetched values only if the requested field was prefetched.
- if name in instance._prefetched_objects_cache:
- return instance._prefetched_objects_cache[name], True
- return default, False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement