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.
Source:stackexchange.com