def post(self, request, format=None): requested_data = json.loads(request.body) print(requested_data) # print(request.data["image"]) """ insert into base user """ username = requested_data["org_id"] email = requested_data["org_id"] password = requested_data["org_password"] base_user = CustomUser(username=username, email=email, is_normaluser=False) base_user.set_password(password) # base_user.save() get_org = CustomUser.objects.get(username=username) print("get organization", get_org.id) try: """ getting request data """ org_type = requested_data['type'] org_category = requested_data["org_category"] org_name = requested_data["name"] org_address = requested_data["address"] org_image = requested_data["image"] org_description = requested_data["description"] website = requested_data["website"] main_coordinator_name = requested_data["main_coordinator_name"] main_coordinator_phone = requested_data["main_coordinator_phone"] main_coordinator_email = requested_data["main_coordinator_email"] sub_coordinator_name = requested_data["sub_coordinator_name"] sub_coordinator_phone = requested_data["sub_coordinator_phone"] sub_coordinator_email = requested_data["sub_coordinator_email"] event_team = requested_data["team"] event_manager_name = requested_data["manager_name"] event_manager_phone = requested_data["manager_phone"] """ update & saving into organization table """ Organization.objects.filter(user=get_org.id).update( type=org_type, org_category=org_category, name=org_name, address=org_address, image=org_image, description=org_description, website=website, main_coordinator_name=main_coordinator_name, main_coordinator_phone=main_coordinator_phone, main_coordinator_email=main_coordinator_email, sub_coordinator_name=sub_coordinator_name, sub_coordinator_phone=sub_coordinator_phone, sub_coordinator_email=sub_coordinator_email, team=event_team, manager_name=event_manager_name, manager_phone=event_manager_phone, ) return Response({"msg": "adding organisation data successfully"}, status=status.HTTP_201_CREATED) except Exception as e: print(e) return Response({"msg": "failed"}, status=status.HTTP_404_NOT_FOUND)
def post(self, request, format=None): requested_data = json.loads(request.body) """ insert into base user """ username = requested_data["org_id"] email = requested_data["org_id"] password = requested_data["org_password"] # CustomUser.objects.filter(username=username,email=email, is_normaluser=False).update_or_create(password=password) try: base_user = CustomUser(username=username, email=email, is_normaluser=False) base_user.set_password(password) base_user.save() except: return Response({"msg": "failed", "error": "username " + username + " already exists"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) get_org = CustomUser.objects.get(username=username) print("get organization", get_org.id) try: """ getting request data """ org_type = requested_data['type'] org_category = requested_data["org_category"] org_name = requested_data["name"] org_address = requested_data["address"] org_image = utils.save_to_file(requested_data["image"], utils.replace_str_with_us(org_name)) org_description = requested_data["description"] website = requested_data["website"] main_coordinator_name = requested_data["main_coordinator_name"] main_coordinator_phone = requested_data["main_coordinator_phone"] main_coordinator_email = requested_data["main_coordinator_email"] sub_coordinator_name = requested_data["sub_coordinator_name"] sub_coordinator_phone = requested_data["sub_coordinator_phone"] sub_coordinator_email = requested_data["sub_coordinator_email"] # event_team = requested_data["team"] # event_manager_name = requested_data["manager_name"] # event_manager_phone = requested_data["manager_phone"] """ update & saving into organization table """ Organization.objects.filter(user=get_org.id).update( type = org_type, org_category = org_category, name = org_name, address = org_address, image = org_image, description = org_description, website = website, main_coordinator_name = main_coordinator_name, main_coordinator_phone = main_coordinator_phone, main_coordinator_email = main_coordinator_email, sub_coordinator_name = sub_coordinator_name, sub_coordinator_phone = sub_coordinator_phone, sub_coordinator_email = sub_coordinator_email, # team = event_team, # manager_name = event_manager_name, # manager_phone = event_manager_phone, ) return Response({"msg": "adding organisation data successfully"}, status=status.HTTP_201_CREATED) except Exception as e: print(e) return Response({"msg": "failed"}, status=status.HTTP_404_NOT_FOUND)