Answer the question
In order to leave comments, you need to log in
How to write data to DurationField in Django 2.2?
Good afternoon
There is a model
class Calls(models.Model):
time = models.DurationField(null=True, blank=True, verbose_name='Продолжительность')
00:20:15
duration = row[2] #Строка из файла
Calls.objects.create( time = duration)
'str' object has no attribute 'days'
Exception Location: ...\django\utils\duration.py in duration_microseconds, line 44
'datetime.datetime' object
'float' object
Answer the question
In order to leave comments, you need to log in
I decided
import datetime as datetime_class # забыл добавить в ответ
duration = datetime.strptime(duration, "%H:%M:%S")
x_duration =datetime_class.timedelta(hours=duration.hour, minutes=duration.minute, seconds=duration.second).total_seconds()
duration = timedelta(seconds = x_duration)
he needs timedelta, not a string, not a date, not a number, but timedelta
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question