我正在尝试在创建新的运输区域时向“ Woocommerce 运输”选项卡及其“ 运输区域”部分添加一个选择字段。我在寻找解决方案时在Woocommerce的官方文档中找到了这一点。
到目前为止,我尝试过的是:
// Fires on 'plugins_loaded' action of WordPress
public function plugins_loaded_action() {
add_filter( 'woocommerce_get_settings_shipping', array( $this, 'shipping_zone_settings_add_city_field' ), 10, 2 );
}
public function shipping_zone_settings_add_city_field( $settings, $current_section ) {
echo 'this runs only for shipping_options section';
/**
* Check the current section for shipping zone
*/
if( $current_section === 'shipping_zones' ) {
// Add city field to settings
$settings[] = array(
array(
'name' => __( 'Zone City', 'woocommerce' ),
'type' => 'title', …Run Code Online (Sandbox Code Playgroud) 我是Django和Python的新手.目前我正在尝试使用Django Admin.
我有三个型号的Django应用程序,这是GoodsItem,SoldGoodsItem和FinishedGoodsItem.models.py是:
from django.db import models
class GoodsItem(models.Model):
name = models.CharField(max_length=255)
size = models.DecimalField(max_digits=4, decimal_places=2)
INCHES = 'IN'
NUMBER = 'NUM'
GOODS_ITEM_SIZE_UNITS = (
(INCHES, 'Inches'),
(NUMBER, '#'),
)
size_unit = models.CharField(
max_length=4,
choices=GOODS_ITEM_SIZE_UNITS,
default=INCHES,
)
def __str__(self):
if(self.size_unit == self.NUMBER):
return "%s #%s" % (self.name, (self.size).normalize())
else:
return "%s %s\"" % (self.name, (self.size).normalize())
class FinishedGoodsItem(models.Model):
date = models.DateField()
goods_item = models.ForeignKey(GoodsItem, on_delete=models.CASCADE, related_name="finished_name")
weight = models.DecimalField(max_digits=6, decimal_places=3)
def __str__(self):
return str(self.goods_item)
class …Run Code Online (Sandbox Code Playgroud) 我有一个 json,它是一个字典列表,如下所示:
我使用 pymysql 从 MySQL 获取它
[{
"id": "123",
"name": "test",
"group": "test_group"
},
{
"id": "123",
"name": "test",
"group": "test2_group"
},
{
"id": "456",
"name": "test2",
"group": "test_group2"
},
{
"id": "456",
"name": "test2",
"group": "test_group3"
}]
Run Code Online (Sandbox Code Playgroud)
我需要对其进行分组,以便每个“名称”只有一个字典,并且它将包含该名称下所有组的列表。像这样的东西:
[{
"id": "123",
"name": "test",
"group": ["test2_group", "test_group"]
},
{
"id": "456",
"name": "test2",
"group": ["test_group2", "test_group3"]
}]
Run Code Online (Sandbox Code Playgroud)
我想得到一些帮助,谢谢!
Spring Security 提供了 Kotlin DSL 以便于配置。这是Spring 博客中的一个示例:
override fun configure(http: HttpSecurity?) {
http {
httpBasic {}
authorizeRequests {
authorize("/greetings/**", hasAuthority("ROLE_ADMIN"))
authorize("/**", permitAll)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我只想允许对特定路径的 POST 请求。在Java中,你可以这样做:
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/greetings").hasRole("ADMIN");
Run Code Online (Sandbox Code Playgroud)
有使用 Kotlin DSL 的示例吗?
python ×2
arrays ×1
django ×1
django-admin ×1
json ×1
kotlin ×1
kotlin-dsl ×1
php ×1
python-3.x ×1
spring ×1
woocommerce ×1
wordpress ×1