How to insert id in csv reading with DJango

0

I have the following question, in which way I can insert an id that I have obtained from another table, in reading a .csv file, which I am importing into my database with the django-import-export library. I have the code in the following way:

def rrhhjornadas_import_csv(request):
    if request.method == 'POST':
        jornada_resource = RRHHJornadasResources()
        dataset = Dataset()
        new_jornada = request.FILES['myfile']

        imported_data = dataset.load(new_jornada.read().decode('utf-8'), modificado_por='JC')
        result = jornada_resource.import_data(dataset, dry_run=True)  # Test the data import
        # Guardamos los datos del archivo seleccionado por el usuario
        archivo = RrhhJornadasArchivos(nombre=new_jornada, descripcion='Jornadas cargadas por archivo: '+str(new_jornada))
        archivo.save()
        if not result.has_errors():
            jornada_resource.import_data(dataset, dry_run=False)  # Actually import now

        return redirect('rrhh:archivo_listar')
    return render(request, 'rrhh/jornadas_empleado/jornada_file.html')
    
asked by Juan Carlos 16.07.2018 в 17:57
source

0 answers