def get(pk=None):
    if pk:
        Sale = model_to_dict(
            Sale.select().where(Sale.id == pk).get())
        return json.dumps(Sale)

    prodcuts = list(Sale.select())
    return json.dumps([model_to_dict(item.get()) for item in prodcuts])
def edit_stock(request, pk):
    data = json.loads(request.data)
    stock = data.get("stock")
    if stock is None:
        raise BadRequest("Stock is required")

    Sale = Sale.update(stock=stock).where(Sale.id == pk).execute()

    return 200, json.dumps(model_to_dict(Sale.select().where(Sale.id == pk).get()))