How to extract data from a Django Queryset

Asked

Viewed 155 times

0

I have a table with some information, the employee’s name, Pis, date and time, the time field records the time of registration on the time clock, these records are all in the same column, for example: Employee 1, has four records, morning entry, morning departure, late entry and late departure, but all these times are in the same column, what I need is to separate it and take its name and times for a new table, but each time in its respective field.

If anyone can help with the logic of this implementation, I am grateful. It may even be before importing the CSV file, because this data is imported from a CSV but the way it is. If I can do this before the import, resolve.

1 answer

0

In importing the file you could do something like this:

Assuming that your model has all the fields mentioned above and the file had the following format: name,Pis,horario1,horario2,horario3,horario4.

for line in file.readlines():
    data = line.split(',')
    funcionario = Funcionario(nome=data[0], pis=data[1], horario1=data[3] ...)
    funcionario.save()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.