File: compat.py

package info (click to toggle)
python-django-mptt 0.13.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,256 kB
  • sloc: python: 4,964; javascript: 317; makefile: 119; sh: 15
file content (11 lines) | stat: -rw-r--r-- 413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
def cached_field_value(instance, attr):
    try:
        # In Django 2.0, use the new field cache API
        field = instance._meta.get_field(attr)
        if field.is_cached(instance):
            return field.get_cached_value(instance)
    except AttributeError:
        cache_attr = "_%s_cache" % attr
        if hasattr(instance, cache_attr):
            return getattr(instance, cache_attr)
    return None