diff --git a/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py b/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py index e3bccd1..ea690d8 100644 --- a/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py +++ b/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py @@ -26,10 +26,10 @@ class Command(BaseCommand): repostajes_creados = 0 for repostaje_data in datos: try: - vehiculo = Vehiculo.objects.get(id=repostaje_data["vehiculo"]) + vehiculo = Vehiculo.objects.get(matricula=repostaje_data["vehiculo_matricula"]) creado = Repostaje.objects.create( - vehiculo_id=vehiculo.id, + vehiculo=vehiculo, fecha=repostaje_data['fecha'], kms=repostaje_data['kms'], litros=repostaje_data['litros'], @@ -43,7 +43,7 @@ class Command(BaseCommand): repostajes_creados += 1 except Vehiculo.DoesNotExist: - self.stderr.write(self.style.ERROR(f"Vehiculo '{repostaje_data['vehiculo']}' no encontrado.")) + self.stderr.write(self.style.ERROR(f"Vehiculo con matrĂ­cula '{repostaje_data['vehiculo_matricula']}' no encontrado.")) self.stdout.write(self.style.SUCCESS(f'Se importaron {repostajes_creados} repostajes correctamente.')) diff --git a/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py b/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py index 861cf2c..e3ae66b 100644 --- a/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py +++ b/ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py @@ -26,7 +26,6 @@ class Command(BaseCommand): vehiculos_creados = 0 for vehiculo_data in datos: creado = Vehiculo.objects.create( - id=vehiculo_data['id'], marca=vehiculo_data['marca'], modelo=vehiculo_data['modelo'], matricula=vehiculo_data['matricula'], diff --git a/ReyMotaAppsDj/reymota/repostajes/serializers.py b/ReyMotaAppsDj/reymota/repostajes/serializers.py index 82cc100..194c512 100644 --- a/ReyMotaAppsDj/reymota/repostajes/serializers.py +++ b/ReyMotaAppsDj/reymota/repostajes/serializers.py @@ -9,6 +9,7 @@ class VehiculoSerializer(serializers.ModelSerializer): class RepostajeSerializer(serializers.ModelSerializer): + vehiculo_matricula = serializers.CharField(source='vehiculo.matricula', read_only=True) class Meta: model = Repostaje - fields = '__all__' # Incluir todos los campos del modelo + fields = [ 'id', 'fecha', 'kms', 'litros', 'descuento', 'importe', 'precioxlitro', 'kmsrecorridos', 'consumo', 'vehiculo', 'vehiculo_matricula']