def post(self, request, *args, **kwargs): user = request.user business = Business.objects.filter(owner=user).first() customer = None id = kwargs.get('id') if id: customer = Customer.objects.get_one_by_business_and_id( business=business, id=id) # print(request.body) if not check_permission(request=request, permission='add_customer'): return HttpResponse(status=401) print(request.body) data = json.loads(request.body.decode()) print(data.get('birthday')) if data.get('birthday'): dt_value = DateTimeField().to_python(data.get('birthday')) dd_value = dt_value.date() dd_formatted = formats.date_format(dd_value, 'Y-m-d') data['birthday'] = dd_formatted if data.get('prefix'): data['prefix'] = data.get('prefix').get('id') if data.get('suffix'): data['suffix'] = data.get('suffix').get('id') # return HttpResponse() # state = N_State.objects.filter(id=data.get('state')).first() # if not state: # return JsonResponse(status=400, data=[{'state':[{'messasge':'Campo requerido'}]}], safe=False) form = CustomerForm(data) if form.is_valid(): print(form.cleaned_data) response = Customer.objects.create_or_update_customer( form.cleaned_data, business=business, customer=customer) if response in Customer.objects.ERRORS: if response == Customer.objects.EMAIL_ERROR: return JsonResponse(status=400, data=[{ 'state': [{ 'messasge': 'Correo Repetido' }] }], safe=False) return JsonResponse(status=400, data=[{ 'state': [{ 'messasge': 'Error al procesar los datos' }] }], safe=False) return JsonResponse(status=201, data=response.serialize()) else: return JsonResponse(form.errors.as_json(), status=400, safe=False)