feature/implementacion de gestor de informacion y archivos minIO
This commit is contained in:
@@ -17,6 +17,14 @@ class DocumentSerializer(serializers.ModelSerializer):
|
||||
read_only_fields = ('id', 'size', 'extension', 'created_at', 'updated_at', 'pedimento_numero')
|
||||
|
||||
def get_pedimento_numero(self, obj):
|
||||
# Si es un diccionario (durante create)
|
||||
if isinstance(obj, dict):
|
||||
pedimento = obj.get('pedimento')
|
||||
if pedimento and hasattr(pedimento, 'pedimento_app'):
|
||||
return pedimento.pedimento_app
|
||||
return None
|
||||
|
||||
# Si es una instancia del modelo (durante retrieve/list)
|
||||
if obj.pedimento:
|
||||
return obj.pedimento.pedimento_app
|
||||
return None
|
||||
@@ -28,9 +36,19 @@ class DocumentSerializer(serializers.ModelSerializer):
|
||||
return value
|
||||
|
||||
def get_fuente_nombre(self, obj):
|
||||
# Método 1: Si la fuente está precargada con select_related
|
||||
if obj.fuente:
|
||||
return obj.fuente.nombre
|
||||
"""Obtiene el nombre de la fuente de forma segura"""
|
||||
if isinstance(obj, dict):
|
||||
fuente = obj.get('fuente')
|
||||
if fuente and hasattr(fuente, 'nombre'):
|
||||
return fuente.nombre
|
||||
return "Desconocido"
|
||||
|
||||
try:
|
||||
if obj.fuente:
|
||||
return obj.fuente.nombre
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return "Desconocido"
|
||||
|
||||
class FuenteSerializer(serializers.ModelSerializer):
|
||||
|
||||
Reference in New Issue
Block a user