N
N
nik90192021-09-03 12:45:45
Django
nik9019, 2021-09-03 12:45:45

How to copy\duplicate data to write to the database?

The essence of the task:

We get data for the sqlite database from the form on the django site.

in the form:
date1
date2
full name
order type
comment

in the model:
date
full name
order type
comment

it is necessary to copy/save the received data for each date of the period between date1 and date2.

rough example and piece of code:

if request.method == "POST":
    orders = Order() #объект модели бд
    date1 = request.POST.get("data1")
    date2 = request.POST.get("data2")
    orders.date = 
#что сделать, чтобы сделать одинаковые записи для каждой даты между date1 и date2 ?
#получить диапазон дней между двух дат, пройти циклом, т.е. прибавить к date1 + 1 день и записать для 
#каждой даты? как сделать это правильно?
    orders.fio = request.POST.get("fio")
    orders.type = request.POST.get("type")
    orders.comment = request.POST.get("comment")

    orders.save()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question