【发布时间】:2020-09-14 21:46:50
【问题描述】:
我正在使用 pip 模块 MultiSelectField 这是我的模型
SALES_CHANNEL = [
('retailer', 'Retailer'),
('wholesaler', 'Wholesaler'),
('consumer', 'Consumer'),
('distributor', 'Distributor'),
('online', 'Online')
]
class ProductModel(basemodel.BaseModel):
name = models.CharField(max_length=200)
mrp = models.DecimalField(
max_digits=10, decimal_places=2,
null=True, blank=True
)
selling_price = models.DecimalField(
max_digits=10, decimal_places=2,
null=True, blank=True
)
upc = models.CharField(max_length=30, null=True, blank=True)
dimensions = models.CharField(max_length=200, null=True, blank=True)
weight = models.CharField(max_length=200, null=True, blank=True)
sku = models.CharField(max_length=200, unique=True)
product_type = models.CharField(
max_length=30, choices=PRODUCT_TYPE, default='goods'
)
sales_channel = MultiSelectField(
choices=SALES_CHANNEL, null=True, blank=True
)
在使用邮递员创建产品时,我的请求正文是:
{
"name": "first unit",
"sku": "first sales chann",
"sales_channel":["retailer", "wholesaler"]
}
但是在 serializer.is_valid() 上,我得到了这个错误:
"sales_channel": [
"\"['retailer', 'wholesaler']\" is not a valid choice."
],
如何在 postman 上为多选字段发布数据?
【问题讨论】:
标签: django django-models django-rest-framework postman django-multiselectfield