About Caching Property Values

You can cache model properties with functools.cached_property decorator:

from functools import cached_property
from django.contrib.auth.models import AbstractUser

def User(AbstractUser):
    @cached_property
    def is_editor(self):
        return self.groups.filter(name="Editors").exists()

Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3