Get the context for outputing raw json in api and admin, no looping over the fields anymore
This commit is contained in:
@@ -74,11 +74,12 @@ class TranslatableMixin:
|
||||
if not self.translatable:
|
||||
return value
|
||||
|
||||
# Check if we're in admin context by looking at the call stack
|
||||
# Check if we're in admin or API context by looking at the call stack
|
||||
frames = inspect.getouterframes(inspect.currentframe())
|
||||
is_admin_context = os.environ.get('DJANGO_ADMIN_OVERRIDE', False) == '1' or any('admin' in frame.filename or 'forms' in frame.filename for frame in frames[:5])
|
||||
is_api_context = any('serializers' in frame.filename or 'rest_framework' in frame.filename or '/api/' in frame.filename for frame in frames[:10])
|
||||
|
||||
logging.debug(f"{self.__class__.__name__} from_db_value - admin context: {is_admin_context}")
|
||||
logging.debug(f"{self.__class__.__name__} from_db_value - admin context: {is_admin_context}, api context: {is_api_context}")
|
||||
|
||||
try:
|
||||
translations = json.loads(value) if isinstance(value, str) else value
|
||||
@@ -87,10 +88,10 @@ class TranslatableMixin:
|
||||
|
||||
logging.debug(f"{self.__class__.__name__} from_db_value - parsed translations: {translations}")
|
||||
|
||||
# For admin/forms, return the full dict so widgets can access all translations
|
||||
if is_admin_context:
|
||||
# For admin/forms/API, return the full dict so serializers/widgets can access all translations
|
||||
if is_admin_context or is_api_context:
|
||||
logging.debug(
|
||||
f"{self.__class__.__name__} from_db_value - returning full dict for admin: {translations}")
|
||||
f"{self.__class__.__name__} from_db_value - returning full dict for admin/api: {translations}")
|
||||
return translations
|
||||
|
||||
# For regular use, return the appropriate language
|
||||
|
||||
Reference in New Issue
Block a user