[Answered ]-How to lazily evaluate ORM call after fixtures are loaded into db in Django?

2👍

I would use the functions instead of the constants, but memoize them:

_cache = {}

def get_page_type(type_name):
    if type_name not in _cache:
        _cache[type_name] = PageType.objects.get(type=type_name)
    return _cache[type_name]

So now you’d call get_page_type('Main') directly when necessary.

Leave a comment