I am having difficulty unifying the format for all the dates, in my database, the format is year month day, and in my form is year month day min second. I want the date format to be unified but i seem to cant do it.
def get_unavailable_dates(request, car_id):
try:
busy_dates = BusyDate.objects.filter(car_id=car_id)
unavailable_dates_list = [busy_date.start_date.strftime('%Y-%m-%d') for busy_date in busy_dates]
except BusyDate.DoesNotExist:
unavailable_dates_list = []
busy_dates_json = [{'title': 'Busy', 'start': busy.start_date, 'end': busy.end_date} for busy in busy_dates]
return JsonResponse(busy_dates_json, safe=False)
def save_busy_dates(request):
if request.method == 'POST':
car_id = request.POST.get('car_id')
busy_dates = request.POST.getlist('busy_dates[]') # Assuming busy_dates is sent as a list
# Iterate over busy_dates list and create BusyDate instances
for date_str in busy_dates:
busy_date = BusyDate(car_id=car_id, start_date=date_str.date(), end_date=date_str.date())
busy_date.save() # Save the instance to the database
return JsonResponse({'status': 'success'})
else:
return JsonResponse({'status': 'error', 'message': 'Invalid request method'}, status=400)```
I tried to add .date() where possible