def post(self, request): '''post方法''' account = check_and_get_str(request.data, "account") password = check_and_get_str(request.data, "password") admin = Auth.objects.filter(account=account, password=password) if not admin: return self.error(err="账号或密码错误") else: token = AuthToken.update_token(admin[0].id) return self.success(data={"token": token})
def get_plus(self, request): nutrition_id = check_and_get_str(request.query_params, "id") try: obj = Nutrition.objects.get(id=nutrition_id) data = IngredientSerializer(obj).data return self.success(data=data) except Exception as e: return self.error(err=str(e))
def get_plus(self, request): nutrition_id = check_and_get_str(request.query_params, "id") try: obj = Nutrition.objects.get(id=nutrition_id) obj.delete() return self.success() except Exception as e: return self.error(err=str(e))
def get(self, request): """ get 方法 """ keyword = check_and_get_str(request.query_params, 'key_word') dishes = DishQueryFunctionSet.keyword(request.user, keyword) serializer = DishWithLikeSerializer(dishes, many=True) try: return self.success(data=serializer.data) except Exception as e: return self.error(err=str(e))
def post_plus(self, request): nutrition_id = check_and_get_str(request.data, "id") try: obj = Nutrition.objects.get(id=nutrition_id) ingredient_obj = IngredientSerializer( instance=obj, data=request.data) if ingredient_obj.is_valid(raise_exception=True): ingredient_obj.save() return self.success() except Exception as e: return self.error(err=str(e))
def post_plus(self, request): raw_data = {} raw_data['name'] = check_and_get_str(request.data, "name") check_one_field(request.FILES, "picture") raw_data["picture"] = request.FILES["picture"] check_one_field(request.data, "ingredient") try: raw_data["ingredient"] = json.loads(request.data["ingredient"]) dish_data = get_dish_data(raw_data) dish_obj = DishSerializer(data=dish_data) if dish_obj.is_valid(raise_exception=True): dish_obj.save() return self.success() except Exception as e: return self.error(err=str(e))