我正在试图弄清楚如何在Django中创建自定义组,以便组与应用程序相关而不是与项目相关.
例如,当用户想要创建公司时,它应该是公司的所有者:
class Company(models.Model):
owner = models.ForeignKey(User)
name = models.CharField(max_length=64, unique=True)
description = models.TextField(max_length=512)
created_on = models.DateTimeField(auto_now_add=timezone.now)
class Meta:
permissions = (
("erp_view_company", "Can see the company information"),
("erp_edit_company", "Can edit the company information"),
("erp_delete_company", "Can delete the company"),
)
Run Code Online (Sandbox Code Playgroud)
# Create your views here.
def register(request, template_name='erp/register.html'):
if request.method == 'POST':
company_form = CompanyRegistrationForm(request.POST)
if company_form.is_valid():
# Create a new company object but avoid saving it yet
new_company = company_form.save(commit=False)
# Set the owner
if request.user.is_authenticated():
new_company.owner …Run Code Online (Sandbox Code Playgroud) 默认情况下,每个django模型都有3个权限(添加,更改,删除).在模型中,我可以定义我的自定义权限以添加更多.
class Company(models.Model):
owner = models.ForeignKey(User)
name = models.CharField(max_length=64, unique=True)
description = models.TextField(max_length=512)
created_on = models.DateTimeField(auto_now_add=timezone.now)
class Meta:
permissions = (
("erp_view_company", "Can see the company information"),
("erp_edit_company", "Can edit the company information"),
("erp_delete_company", "Can delete the company"),
)
Run Code Online (Sandbox Code Playgroud)
迁移时,会在数据库级别自动创建这些权限.如何从模型中检索所有权限?
# retrieves the permissions
permissions = Permission.objects.filter(get_all_permissions_of_model_Company)
# adds permissions to group
group = Group.objects.create(name='foo', permissions=permissions)
# adds user to group
user.groups.add(group)
Run Code Online (Sandbox Code Playgroud) 正如 Vuex 文档所述,当项目开始增长时,我们需要一种方法在更加独立和模块化的可扩展解决方案中分离状态管理。这里命名空间可以派上用场。遗憾的是,在撰写 Vuex 模块部分时,缺乏如何有效使用它们的信息和示例。
这是我的商店结构
store
|- modules
|- core
|- country.js
|- region.js
|- ...
|- roullout
|- site.js
|- index.js
Run Code Online (Sandbox Code Playgroud)
这里模块注册index.js
store
|- modules
|- core
|- country.js
|- region.js
|- ...
|- roullout
|- site.js
|- index.js
Run Code Online (Sandbox Code Playgroud)
现在在某些组件中我尝试定义操作
import Vuex from 'vuex'
// Core modules
import coreCountry from "@/store/modules/core/country";
import coreRegion from "@/store/modules/core/region";
// Rollout modules
import rolloutSite from "@/store/modules/rollout/site";
export default new Vuex.Store({
modules: {
// Core modules
core: {
country: coreCountry,
region: coreRegion, …Run Code Online (Sandbox Code Playgroud) 任何人都知道如何通过C和CUDA中改进的Gram-Schmidt方法进行QR分解.一些例子/来源/纸张或其他?非常感谢.
编辑:我无法回答我的问题,因为有人关闭了它,所以我决定更新我的问题.
/*
* QR decomposition via modified Gram-Schmidt algorithm
*
* @Package = QR-decomposition
* @Program = QR_gpu
* @Version = 13.0928
*/
// Libraries
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <cuda.h>
// Constant
#define PROG "QR_cpu"
#define VERSION "13.1003"
#define PACKAGE "QR-Decomposition"
// Threads per block
#define THREAD_P_BLOCK 512
// Blocks per grid
#define BLOCKS_P_GRID 512
// macro
/* wrap each API call with the gpuErrchk macro, which will …Run Code Online (Sandbox Code Playgroud) django ×2
permissions ×2
python ×2
c ×1
cuda ×1
inheritance ×1
usergroups ×1
vue.js ×1
vuex ×1
vuex-modules ×1