Given a table that looks like this:
name
------
barry
dave
bill
dave
dave
barry
john
This query:
SELECT name, count(*) AS count FROM table GROUP BY name;
Will produce output like this:
name count
-------------
barry 2
dave 3
bill 1
john 1
Run Code Online (Sandbox Code Playgroud)
这里ActiveModel使用COUNT执行GROUP BY的正确Rails约定是什么?
我正在使用Django paypalrestsdk for PayPal https://github.com/paypal/PayPal-Python-SDK
我想设置一个月度订阅计划.每个月初,买家将收取100美元的费用.
这是我制作的结算方案代码:
billing_plan = paypalrestsdk.BillingPlan({
"name": "Monthly Billing Plan",
"description": "Monthly Plan",
"merchant_preferences": {
"auto_bill_amount": "yes",
"cancel_url": "http://localhost:8000/payment_billing_agreement_cancel",
"initial_fail_amount_action": "continue",
"max_fail_attempts": "0",
"return_url": "http://localhost:8000/payment_billing_agreement_execute",
"setup_fee": {
"currency": "USD",
"value": "100"
}
},
"payment_definitions": [
{
"amount": {
"currency": "USD",
"value": "100"
},
"cycles": "0",
"frequency": "MONTH",
"frequency_interval": "1",
"name": "Monthly Payment",
"type": "REGULAR"
}
],
"type": "INFINITE"
})
Run Code Online (Sandbox Code Playgroud)
我不清楚它是在月的第一天还是在月的最后一天收费?我应该进行设置,以便立即收费吗?我的意图是收费是在每个月的第一天完成的.
我在买家的沙箱中看到这个:预先批准的付款USD100这是什么意思,他已经收取100美元或预先批准并在当月的最后一天收费?
基于此,它似乎立即收费.这意味着它应该显示200美元吗?(设置+每月但仅显示100美元) https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/subscription_billing_cycles/
到目前为止我用过这个流程:
create billing plan
activate billing plan
create billing agreement
execute billing agreement …Run Code Online (Sandbox Code Playgroud) 我希望onesignal能够将推送通知发送到特定设备.
如何捕获设备的设备ID?
我使用什么API推送到特定设备?
谢谢.
当应用程序运行或未运行时,我想在远程iphone/android设备上发出警报.
我该如何实现?
当有来电时,我只能想到Whatsapp/Skype,它响了.或者是否可以使手机在推送通知上播放循环闹钟声音.
另一个非常明显的例子是"查找我的iPhone"应用程序,它可以触发iPhone的响亮警报.
如何在ios和android上以编程方式实现此目的?
我希望能够将上传的图像调整为各种尺寸类别:
并将其保存到AWS S3.后来才能访问它.一种策略是将其保存在filename_small.jpg,filename_medium.jpg中,有一个辅助函数,可以附加_small,_medium来访问这些文件.我不知道如何保存所有不同的文件(调整大小),然后使用帮助程序访问它.
https://gitlab.com/firdausmah/railercom/blob/master/railercomapp/storage_backends.py
class MediaStorage(S3Boto3Storage):
location = 'media'
file_overwrite = False
Run Code Online (Sandbox Code Playgroud)
https://gitlab.com/firdausmah/railercom/blob/master/railercomapp/models.py
class Employee(models.Model):
...
face_image = models.FileField(upload_to=upload_to('employee/face_image/'), blank=True, storage=MediaStorage())
Run Code Online (Sandbox Code Playgroud)
https://gitlab.com/firdausmah/railercom/blob/master/railercomapp/api.py
@api_view(['POST'])
def update_employee_image(request):
...
employee = Employee.objects.get(id = employee_id)
employee.face_image = face_image_obj
employee.save()
Run Code Online (Sandbox Code Playgroud)
我正在使用django-storages和S3Boto3Storage.我的完整工作项目是在git链接中.
我有一个 firebase 函数代码,有很多 Lint 问题。我怎样才能用--fix修复这些问题。它显示在错误消息的末尾。
\n\n\n火力基地部署
\n
/Users/xxx/firebase/functions/index.js\n 16:1 error Unexpected tab character no-tabs\n 16:1 error Expected indentation of 6 spaces but found 1 tab indent\n .....\n 69:1 error Unexpected tab character no-tabs\n 69:1 error Expected indentation of 6 spaces but found 1 tab indent\n 69:5 error Trailing spaces not allowed no-trailing-spaces\n 69:5 error Block must not be padded by blank lines padded-blocks\n 71:1 error Trailing spaces not allowed no-trailing-spaces\n\n\xe2\x9c\x96 157 problems (157 errors, 0 warnings)\n 45 …Run Code Online (Sandbox Code Playgroud) 我在mongoid 3.1.0和最新3.1.3的rails中试过这样的东西..limit不起作用.下面它应该返回1行,但它返回所有(4)
码:
@go = Gallery.limit(1)
logger.info "count: #{@go.count}"
Run Code Online (Sandbox Code Playgroud)
输出:
count: 4
MOPED: 54.234.11.193:10055 QUERY database=mongohqtestdatabase collection=galleries selector= {"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (276.2010
Run Code Online (Sandbox Code Playgroud)
女士)
哪个版本的mongoid与limit()有关?
这是我的问题的后续跟进:ImageField/FileField Django表单目前无法修剪文件名的路径
在我的Django应用程序中,有一个上传到S3的图像字段修剪图像文件路径名后,由于修剪了网址,因此无法访问该图像.我如何修剪显示但不修剪路径?
我设法修剪显示文件名的显示
class CustomClearableFileInput(ClearableFileInput):
def get_context(self, name, value, attrs):
logging.debug("%s",name)
logging.debug("%s",value)
value.name = path.basename(value.name)
context = super().get_context(name, value, attrs)
return context
class CompanySettingEdit(forms.ModelForm):
company_logo = forms.ImageField(widget=CustomClearableFileInput)
Run Code Online (Sandbox Code Playgroud)
这是输出:
https://imgur.com/a/M42Mz <-- display correct
https://bucketname.s3.amazonaws.com/media/certiport_logo.png <-- invalid url
Run Code Online (Sandbox Code Playgroud)
如果我不修剪它:
class CustomClearableFileInput(ClearableFileInput):
def get_context(self, name, value, attrs):
logging.debug("%s",name)
logging.debug("%s",value)
# value.name = path.basename(value.name) <-- remove this
context = super().get_context(name, value, attrs)
return context
class CompanySettingEdit(forms.ModelForm):
company_logo = forms.ImageField(widget=CustomClearableFileInput)
Run Code Online (Sandbox Code Playgroud)
这是输出:
https://imgur.com/a/rGi8f <-- display incorrect
https://bucketname.s3.amazonaws.com/media/company_logo/15/certiport_logo.png <--valid url
Run Code Online (Sandbox Code Playgroud)
我的目标是:
display: certiport_logo.png
url: https://bucketname.s3.amazonaws.com/media/company_logo/15/certiport_logo.png …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Postgres PostGIS在Ruby On Rails上执行此操作.
我正在尝试进行分组并依靠我所拥有的有序列表中的城市.
我有一个最近点到我坐标的有序列表(110.1862202 1.6031959).
现在我想按城市分组并计算每个城市的项目数量.但是,格式是正确的,但不知何故它已经失去了它的排序.我希望这些城市的排序最接近我的坐标.最重要的是要到最近的城市,但现在它没有排序最近.
查询问题组和计数子查询
scope :nearestcitysubquery, -> () {
from(Treasure.order("ST_Distance(treasures.location_point,
ST_GeographyFromText('SRID=4326;POINT(110.1862202 1.6031959)'))"),
"subquery_treasure_nearest").group("city").count
}
Run Code Online (Sandbox Code Playgroud)
实际结果
=> {"Kuala Lumpur"=>1, "null"=>1, "Sungai Besar"=>1, "Sungai Udang"=>1, "Kuching"=>1}
Run Code Online (Sandbox Code Playgroud)
预期结果
=> {"Kuching"=>1, "Sungai Besar"=>1, "Sungai Udang"=>1, "Kuala Lumpur"=>1, "null"=>1}
Run Code Online (Sandbox Code Playgroud)
我的订购查询工作正常
Treasure.order("ST_Distance(treasures.location_point,
ST_GeographyFromText('SRID=4326;POINT(110.1862202 1.6031959)'))")
Run Code Online (Sandbox Code Playgroud)
订购结果(这是正确的)
=> #<ActiveRecord::Relation [#<Treasure id: 5, user_id: 1, treasure_name: "Kucing", treasure_image: nil, description: "Kucing", hint: nil, location: "Jalan Ke Puncak Serapi", created_at: "2016-01-08 03:46:40", updated_at: "2016-01-08 03:46:40", treasure_id: "TRKKY", location_point: #<RGeo::Geographic::SphericalPointImpl:0x3fe9942b71c8 "POINT (110.18 1.6)">, city: "Kuching", state: …Run Code Online (Sandbox Code Playgroud) 我有这个Django REST API,我想自定义json响应的列表查询结果.原因是因为日期格式化以及可能的其他格式化.
这是Rest API,问题是created_at我希望它的格式如下:('%Y-%m-%d%H:%M').以下代码没有任何格式,它只会列出并在结果上创建一个json.
@api_view(['POST'])
def employee_get_list_by_page(request):
val_params = ["id", "username","first_name","last_name","created_at"]
employee_list = Employee.objects.all().values(*val_params).order_by('id')
page = request.GET.get('page', request.POST['page'])
paginator = Paginator(employee_list, request.POST['page_limit'])
try:
employees = paginator.page(page)
except PageNotAnInteger:
employees = paginator.page(request.POST['page'])
except EmptyPage:
employees = paginator.page(paginator.num_pages)
return Response(list(employees), status=status.HTTP_200_OK)
Run Code Online (Sandbox Code Playgroud)
这是模型.注意我有.as_dict()函数.对于个人记录,比如使用emp = Employee.objects.get(id = 6),我可以这样做emp.as_dict(),结果将在created_at中具有格式化日期.
class Employee(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='employee')
company = models.ForeignKey(Company)
username = models.CharField(max_length=30, blank=False)
first_name = models.CharField(max_length=30, blank=False)
last_name = models.CharField(max_length=30, blank=False)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.user.username
def as_dict(self):
return {"id": "%d" % …Run Code Online (Sandbox Code Playgroud)