我正在构建颜色的整数数组字段。
我尝试使用CommaSeparatedIntegerField,但它已被删除
CommaSeparatedIntegerField has been deprecated.
Support for it (except in historical migrations) will be removed in Django 2.0.
HINT: Use CharField(validators=[validate_comma_separated_integer_list]) instead
所以我使用了将颜色字段设置为CharField
而不是CommaSeparatedIntegerField
作为推荐
from django.core.validators import validate_comma_separated_integer_list
class Cloth(models.Model):
color = models.CharField(validators=validate_comma_separated_integer_list)
但是我在制作游戏时遇到了这个错误
TypeError: 'RegexValidator' object is not iterable
为什么我收到此错误?我遵循了确切的准则:(
答案 0 :(得分:5)
首先CharField
需要max_length
字段,而validators
需要list
[]
所以,
class Cloth(models.Model):
color = models.CharField(validators=[validate_comma_separated_integer_list],max_length=100)