0

i need some help with this python code, i am trying to generate some time data based on user input but i keep getting an error :

AttributeError: type object 'datetime.datetime' has no attribute 'datetime'

I have tried several import statements like: from datetime import datetime, timedelta and also import datetime but the error persists. kindly help since i cant get my head around this.

def generate_time_slots(available_from, available_to):
    entry = []
    while available_from <= available_to:
        available_from = datetime(available_from).time() + datetime.timedelta(minutes=10).time()

        entry.append(doctor_id = '1', date = '2018-07-11', avalable_slots= available_from,)
        for x in entry:
            Slots.objects.bulk_create(entry)
Baptiste Mille-Mathias
  • 2,144
  • 4
  • 31
  • 37
  • The number of questions of this type are the proof of how bad this lib was named... – scharette Jul 09 '18 at 17:34
  • Yes, i read those answers but i still did fully comprehend until nosklo gave his explanation below. Sorry if you are offended by my question. But sometimes you just need someone else to explain using different set of words. – Medical Doctor - Programmer Jul 09 '18 at 18:03
  • I'm not offended by your question at all. But just remember there is a reason why @nosklo marked it as a **duplicate**. I understand that sometimes you understand better from certain peoples' explanations. But I will hardly believe you couldn't find any explanation on Stack about this specific problem since there is several threads on this error already (dupe included, answer are almost the same as accepted answer). Just Google it in the future, its good practice. – scharette Jul 09 '18 at 18:06

1 Answers1

1

You used from datetime import datetime which means your datetime name is already pointing to datetime.datetime. If you try to access datetime.datetime you will end up accessing datetime.datetime.datetime which doesn't exist.

You should use just import datetime instead, and in your code use datetime.datetime and datetime.timedelta, but if you still want to use from datetime import datetime, timedelta, you have to change all datetime.datetimes in your code to say only datetime and datetime.timedelta to say only timedelta.

nosklo
  • 217,122
  • 57
  • 293
  • 297