본문 바로가기
Django 장고

장고 date가 'null' 로 들어가서 나는 에러 해결

by jennyiscoding 2024. 7. 2.

장고 date가 'null' 로 들어가서 나는 에러 해결

에러메세지: 

[2024-07-02 17:48:25,232] INFO [machinesiteapp.views:273] [user:super(super) app:F] site edit false : {'site_build_date': [ErrorDetail(string='Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].', code='invalid')], 'audit_start_date': [ErrorDetail(string='Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].', code='invalid')], 'audit_end_date': [ErrorDetail(string='Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].', code='invalid')], 'year': [ErrorDetail(string='A valid integer is required.', code='invalid')]}

 

해결방법:

				else :
					for key, value in data.items():
						if key in ['site_build_date', 'code', 'audit_start_date', 'employee_list', 'audit_end_date', 'year']:
							if value == 'null':
								data[key] = None
					report_form = get_object_or_404(MachineReportForm, id = int(data['form_id']))
					site_serializer = MachineSiteEditSerializer(report_form.site_edit, data=data, partial=True)