#🔒 Why doesn't it read the time that I have in the database?

5 messages · Page 1 of 1 (latest)

eager igloo
#

Hello everyone, I have a problem related to booking a time taking into account the coach’s training segment. when I want to choose a date for booking, for example, it tells me that there are no available times for M.D.Y
.
what do I need to do or how to implement the method so that I can select the date and time for booking taking into account the coach’s time period, that is, not from 00:00 to 23:45, and for example from 11:00 to 18:00, depending on coach and what is his schedule

    if request.method == 'GET':

        current_trainer_description = TrainerDescription.objects.get(id=trainer_id)
        specific_service = Service.objects.get(id=service_id, trainer=current_trainer_description.trainer)

        selected_date_str = request.GET.get('training_date')
        selected_date = None
        if selected_date_str:
            selected_date = datetime.strptime(selected_date_str, "%Y-%m-%d").date()

        print(f"Selected Date: {selected_date}")

        schedules = TrainerSchedule.objects.filter(
            trainer=current_trainer_description.trainer,
            datetime_start__date=selected_date
        )

        print(f"Schedules: {schedules}")

        available_times = []
        for schedule in schedules:
            start_time = schedule.datetime_start
            end_time = schedule.datetime_end

            if isinstance(start_time, int):
                start_time = datetime.fromtimestamp(start_time / 1000)
            if isinstance(end_time, int):
                end_time = datetime.fromtimestamp(end_time / 1000)


            available_times.append((start_time, end_time))

        print(f"Available times: {available_times}")

        context = {
            'available_times': available_times,
            'specific_service': specific_service,
            'selected_date': selected_date,
        }
        return render(request, 'trainer_service_page.html', context)
pastel basinBOT
#

@eager igloo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @eager igloo!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
pastel basinBOT
#

@eager igloo

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.