@마크다운
def validate(self, data, **kwargs):
start_lesson_date = data['start_lesson_date']
end_lesson_date = data['end_lesson_date']
tutor = get_object_or_404(Tutor, pk=data['tutor'].pk)
customer = get_object_or_404(SnowPeopleUser, pk=data['customer'].pk)
print(tutor, customer)
schedule_of_lesson = (end_lesson_date + timedelta(hours=1)) - start_lesson_date
reservated_list = [start_lesson_date + timedelta(hours=n) for n in range(schedule_of_lesson.seconds // 3600)]
disable_date_list = [i.date for i in tutor.disable_days.all()]
print(disable_date_list)
for day in reservated_list:
if day in disable_date_list:
raise serializers.ValidationError('이미 예약이 되어있는 날짜를 선택하셨습니다.')
return data
def save(self, *args, **kwargs):
start_lesson_date = self.validated_data.get('start_lesson_date', '')
end_lesson_date = self.validated_data.get('end_lesson_date', '')
customer = get_object_or_404(SnowPeopleUser, pk=self.validated_data.get('customer', '').pk)
tutor = get_object_or_404(Tutor, pk=self.validated_data.get('tutor', '').pk)
Reservation.objects.create(
customer=customer,
tutor=tutor,
start_lesson_date=start_lesson_date,
end_lesson_date=end_lesson_date,
reservation_person=self.initial_data.get('reservation_person'),
)
schedule_of_lesson = (end_lesson_date + timedelta(hours=1)) - start_lesson_date
reservated_list = [start_lesson_date + timedelta(hours=n) for n in range(schedule_of_lesson.seconds // 3600)]
for date in reservated_list:
date_instance, _ = disable_time.objects.get_or_create(tutor=tutor, date=date)
tutor.disable_days.add(date_instance)
이건 그냥 안까먹으려고 적어둠
'etc' 카테고리의 다른 글
다른사람의 코드를 다른서버로 옮기기(elastic beanstalk,requirements.txt is invalid) (0) | 2017.10.09 |
---|---|
17-09-14 장고에서 다중유저모델 쓰는법 (django multi user model) (0) | 2017.09.14 |
AWS Route53 설정하기 (0) | 2017.09.08 |
유저 모델링 실수 (migrations history error) (0) | 2017.09.06 |
Login 시나리오 (1) | 2017.08.29 |