我收到一个我不明白的错误!
无法导入名称项
在我的模型中,我有物品.这些项目是行动所必需的.但其中一些项目对行动有影响:
项目
from django.db import models
from effects.models import Effect
class Type(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Item(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=200)
type = models.ForeignKey(Type)
quality = models.IntegerField()
effects = models.ManyToManyField(Effect,through='ItemEffect',blank=True)
item_requirement = models.ManyToManyField('self',through='ItemCraft',symmetrical=False,blank=True)
points = models.IntegerField()
def __unicode__(self):
return self.name
class Food(Item):
ap = models.IntegerField()
class Tool(Item):
durability = models.IntegerField()
[....]
class ItemEffect(models.Model):
item = models.ForeignKey(Item)
effect = models.ForeignKey(Effect)
def __unicode__(self):
return self.item.name+':'+str.lower(self.effect.name)
class Meta:
verbose_name_plural = 'items effects'
class ItemCraft(models.Model):
item …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中设置一个“点赞”系统。用户应该能够喜欢帖子或评论(当然是帖子的评论)。我应该如何设计这个?
用户
const userSchema = new Schema({
id: { type: String, required: true },
username: { type: String, required: true },
password: { type: String, required: true },
});
Run Code Online (Sandbox Code Playgroud)
帖子
const postSchema = new Schema({
content: { type: String, required: true },
authorId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true }
});
Run Code Online (Sandbox Code Playgroud)
评论
const commentSchema = new Schema({
content: { type: String, required: true },
authorId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
postId: { type: mongoose.Schema.Types.ObjectId, ref: "Post", …Run Code Online (Sandbox Code Playgroud) 我有一个用户列表,如果我点击此列表中的项目,则会打开一个窗口.这是每个用户的相同窗口,并且可以同时打开多个窗口.该窗口显示用户信息,因此对于此组件,我具有相同的存储和相同的模型.
但是如果我在特定窗口中加载数据,我会在所有其他打开的窗口中加载相同的数据.
Ext.define('Cc.view.absence.Grid', {
extend: 'Ext.grid.Panel',
alias: 'widget.absencegrid',
border:false,
initComponent: function() {
Ext.apply(this, {
store: Ext.create('Ext.data.Store', {
model: 'Cc.model.Absence',
autoLoad: false,
proxy: {
type: 'ajax',
reader: {
type: 'json'
}
}
}),
columns: [
{header: 'Du', dataIndex: 'startdate', flex: 3, renderer: this.formatDate},
{header: 'Au', dataIndex: 'enddate', flex: 3, renderer: this.formatDate},
{header: 'Exercice', dataIndex: 'year', align: 'center', flex: 1},
{header: 'Statut', xtype:'templatecolumn', tpl:'<img src="../images/status-{statusid}.png" alt="{status}" title="{status}" />', align: 'center', flex: 1},
{header: 'Type d\'absence', dataIndex: 'absencetype', align: 'center', flex: 2},
{header: …Run Code Online (Sandbox Code Playgroud) 我有数组的键可以是真正的字符串
var array = {
'Blue' : 1,
'Red' : 2,
'Green': 3
}
Run Code Online (Sandbox Code Playgroud)
或者它可能是数字,但有时浮动被视为字符串,我想因为它不是一个数组而是一个对象:
var array = {
9 : 1,
'9.5' : 2,
10 : 3
'10.5': 4
}
Run Code Online (Sandbox Code Playgroud)
这个不是一个数组,所以如果我想保留原始顺序,我需要对它进行排序:
$.each(Object.keys(array).sort(function(a, b) {
var anum = parseFloat(a),
bnum = parseFloat(b);
return anum - bnum;
}), function(index, value) {
……
});
Run Code Online (Sandbox Code Playgroud)
如果我不这样做,我的阵列是:
var array = {
9 : 1,
10 : 3,
'9.5' : 2
'10.5': 4
}
Run Code Online (Sandbox Code Playgroud)
我需要保持它的排序.我的解决方案运行良好但我需要检查密钥是数字还是字符串.如果它们是字符串,我不需要对数组进行排序.就像是:
$.each(/*if my array has numbers as keys I sort the …Run Code Online (Sandbox Code Playgroud) 我有一个脚本bash来从.txt文件添加用户.这很简单:
name firstname uid gid
Run Code Online (Sandbox Code Playgroud)
空间分隔值
我想用awk检查每行是否包含4个字段.如果是,我想返回1,如果不返回0.
file=/my/file.txt
awk=$(awk -F' ' '{(NF != 4) ? res = 0 : res = 1; print res)}' $file)
echo $awk
Run Code Online (Sandbox Code Playgroud)
现在,awk每行返回1,但我希望它在结尾返回1或0,而不是文件中的每一行.
const jwt = require("jsonwebtoken");
const SECRET = "superSuperSecret";
module.exports = function(req, res, next) {
const token = req.body.token || req.query.token || req.headers[ "x-access-token" ];
if (token) {
return jwt.verify(token, SECRET, function(err, decoded) {
if (err) {
return res.json({
success: false,
message: "Failed to authenticate token.",
});
}
req.user = decoded;
return next();
});
}
return res.unauthorized();
};
Run Code Online (Sandbox Code Playgroud)
我正在使用Postman测试我的API。我用x-access-token键和value 设置标题superSuperSecret。我弄错了{"name":"JsonWebTokenError","message":"jwt malformed","level":"error"}。我正在使用这个https://github.com/FortechRomania/express-mongo-example-project/blob/master/src/middlewares/validateToken.js
我试图得到类似的东西:
我正在使用 Bulma,目前我正在使用带有is_multiline选项的列。但我唯一能得到的是:
我想消除卡片之间的差距,我想使用更多的 flexbox 选项。它也必须是响应式的。
.card-columns {
column-count: 1;
column-gap: 1.5rem;
padding: 1.5rem;
}
.card-columns .card {
display: inline-block;
width: 100%;
margin-bottom: 1.5rem;
}
.columns-6 {
column-count: 6;
}
.columns-5 {
column-count: 5;
}
.columns-4 {
column-count: 4;
}
.columns-3 {
column-count: 3;
}
.columns-2 {
column-count: 2;
}
.columns-1 {
column-count: 1;
}
@media (max-width: 768px) {
.columns-6-mobile {
column-count: 6;
}
.columns-5-mobile {
column-count: 5;
}
.columns-4-mobile {
column-count: 4;
}
.columns-3-mobile { …Run Code Online (Sandbox Code Playgroud)