过去,许多管理员使用sms-gate从他们的系统发送重要信息,例如"断电,UPS正在工作!","上电,UPS关闭!" 或"CPU温度过高!".今天在Facebook时代,我们使用信使而不是短信,所以我想知道我是否可以为这样的事情创建一个命令行bash或php脚本.
这个想法 - cron每隔10分钟检查一次这个条件,如果是真的,就向我的信使发送消息.
问题:
我找到了通知应用程序,但我认为它不会向Messenger发送消息,所以它将毫无用处.
该模型:
class Operation(models.Model):
operation_type = models.ForeignKey(OperationType)
category = models.ForeignKey(Category, default=0)
related_account = models.ForeignKey(Account, related_name = 'related_account', null = True)
comments = models.TextField(null = True)
Run Code Online (Sandbox Code Playgroud)
代码:
def detail(request, category_id):
class OperationCategoryOnlyForm(forms.ModelForm):
class Meta:
model = Operation
fields = ('operation_type', 'category', 'related_account', )
from django.forms.models import modelformset_factory
OperationFormSet = modelformset_factory(Operation, form=OperationCategoryOnlyForm)
if request.method == "POST":
formset = OperationFormSet(request.POST, queryset=Operation.objects.filter(category=category_id))
if formset.is_valid():
formset.save()
# HERE IS THE FORMSET, WHICH OVERLAPS THE POSTED FORMSET - this was intentionaly to get the current result not …Run Code Online (Sandbox Code Playgroud) 我正在尝试将json对象导入变量.我根据教程使用服务.
我收到意外的令牌错误,因为我不应该使用 $scope.news = JsonSource.feed();- 但我真的不知道我应该使用什么.我用Google搜索并搜索了3个小时,我发现只有$ http.或$ json.答案,但我觉得,它可以做得更容易 - 更清楚.
(完美的解决方案是$scope.news = JsonSource.feed().entries; D.
服务文件:
var AAAServices = angular.module('AAAServices', [
'ngResource'
]);
AAAServices.factory('JsonSource', ['$resource',
function($resource) {
return $resource('https://www.facebook.com/feeds/page.php', {}, {
feed: {method:'JSONP', {format: 'json', id:'459908', callback : JSON_CALLBACK}, isArray:false}
});
}]);
Run Code Online (Sandbox Code Playgroud)
控制器文件:
var AAAControllers = angular.module('AAAControllers', [])
AAAControllers.controller('newsCtrl', ['$scope', 'JsonSource',
function newsCtrl($scope, JsonSource) {
$scope.news = JsonSource.feed();
}]);
Run Code Online (Sandbox Code Playgroud)
json文件(差不多; D)
{
"title": "Tytu?",
"link": "https:\/\/www.facebook.com\/",
"entries": [
{
"title": " news 1",
"id": "1"
},
{
"title": …Run Code Online (Sandbox Code Playgroud) 模型:
class Store(models.Model):
name = models.CharField(max_length = 20)
class Admin:
pass
def __unicode__(self):
return self.name
class Stock(Store):
products = models.ManyToManyField(Product)
class Admin:
pass
def __unicode__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length = 128, unique = True)
parent = models.ForeignKey('self', null = True, blank = True, related_name='children')
(...)
def __unicode__(self):
return self.name
mptt.register(Product, order_insertion_by = ['name'])
Run Code Online (Sandbox Code Playgroud)
admin.py:
from bar.drinkstore.models import Store, Stock
from django.contrib import admin
admin.site.register(Store)
admin.site.register(Stock)
Run Code Online (Sandbox Code Playgroud)
现在,当我查看管理站点时,我可以从列表中选择任何产品.但我想有一个有限的选择 - 只留下.在mptt类中有功能:
is_leaf_node() - 如果模型实例是叶节点(它没有子节点),则返回True,否则返回False.
但我不知道如何连接它
我正在尝试创建一个子类:在admin.py中:
from bar.drinkstore.models import Store, …Run Code Online (Sandbox Code Playgroud) 可能重复:
自动以正确的编码打开文件
我的代码:
import csv
def handle_uploaded_file(f):
dataReader = csv.reader(f, delimiter=';', quotechar='"')
for row in dataReader:
do_sth
Run Code Online (Sandbox Code Playgroud)
问题是,仅当csv是UTF-8编码时,它才能很好地工作。服务iso-8859-2或Windows-1250编码应更改什么?(最好的解决方案是自动识别编码,但也可以手动转换)
我想用map来获取字符串列表:
value = '1, 2, 3'
my_list = list(map(strip, value.split(',')))
Run Code Online (Sandbox Code Playgroud)
但得到了:
NameError: name 'strip' is not defined
Run Code Online (Sandbox Code Playgroud)
预期结果: my_list=['1','2','3']
得到了非常复杂的查询(请不要尝试解决示例 - 问题更复杂)
crit=[]
crit.append(Q(firstcond = name) | Q(firstcond__isnull = True)
crit.append(Q(secondcond = name) | Q(firstcond__isnull = True)
MyObject.objects.filter(reduce(operator.and_, crit))
Run Code Online (Sandbox Code Playgroud)
这按预期工作:
WHERE (firstcond = name OR firstcond IS NULL) AND (secondcond = name OR secondcond IS NULL)
Run Code Online (Sandbox Code Playgroud)
但现在我需要一些 OR:
WHERE ((firstcond = name OR firstcond IS NULL) AND (secondcond = name OR \
secondcond IS NULL)) OR (third = value)
Run Code Online (Sandbox Code Playgroud)
我无法添加第三个 int crit 列表,因为在 reduce 中使用 operator.and_。我必须在reduce之后添加operator._or,但是如何?
如果我使用输入类型=“数字”,则默认键盘在移动设备上为数字。但我更喜欢 type="text",因为我的输入是可以以 0 开头的 PIN,并且我需要一些其他属性:minlength、maxlength、pattern
我想知道是否可以在移动设备上强制使用除数字和电话之外的其他类型的数字键盘?
我尝试运行schedule.bat:
@echo off
C:\scripts\batch1.bat
C:\scripts\batch2.bat
C:\scripts\batch3.bat
Run Code Online (Sandbox Code Playgroud)
每个batchx.bat的位置是:
@echo off
pushd "C:\otherfolder\"
echo "start batch1"
someprogram.exe parameter1
echo "batch1 end"
popd
Run Code Online (Sandbox Code Playgroud)
(不同的参数,有时更多的一些程序,所以我不能在循环中做到这一点)
当我尝试运行schedule.bat时,它只执行第一个bat(在本例中为batch1)
当我将内容复制到一个蝙蝠 - 它正常工作,所以这对我的程序没有问题 - 批处理1结束也是schedule.bat ...
django ×3
python ×2
admin ×1
angularjs ×1
bash ×1
batch-file ×1
bootstrap-4 ×1
cmd ×1
command-line ×1
csv ×1
encoding ×1
facebook ×1
forms ×1
html ×1
json ×1
linux ×1
map-function ×1
python-3.x ×1
windows ×1