0

我正在尝试schemamigration在我的模型上使用南(我正在使用django 1.4 and python 2.6 on ubuntu

最初我的模型是

class Review(models.Model):
    reviewdate=models.DateField(default=date.today)
    description=models.TextField()
    author=models.ForeignKey(User,null=True)

我添加了一个字段

from django.core.validators import MinValueValidator,MaxValueValidator

class Review(models.Model):
    reviewdate=models.DateField(default=date.today)
    description=models.TextField()
    author=models.ForeignKey(User,null=True)
    rating = models.IntegerField(MinValueValidator(1),MaxValueValidator(10),default=5,help_text='integers 1 to 10')

当我跑步时

python manage.py schemamigration myapp --auto

我明白了TypeError

...
File "/home/me/Django-1.4/django/db/models/base.py", line 198, in __new__
    new_class._prepare()
  File "/home/me/Django-1.4/django/db/models/base.py", line 255, in _prepare
    cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields]))
TypeError: Error when calling the metaclass bases
    sequence item 6: expected string, MaxValueValidator found

有人可以告诉我我错在哪里吗?

4

1 回答 1

1

你的语法不正确。您应该将验证器作为validators参数列表提供:

models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(10)], default=5, help_text='integers 1 to 10')

有关更多信息,请参阅在实践中使用验证的文档。

于 2012-11-28T07:58:16.947 回答