Py学习  »  Django

如何从django内置的唯一字段验证erro响应中删除第三个括号“[]”

Sreebash Chandra Das • 3 年前 • 1500 次点击  

这是我的模型

在这个CustomerAdd表中,我用Django builtins unique=True设计了customer_手机。对于这些独特的领域,Django提出 验证错误如下: { “客户电话”:[ “此客户电话已注册。” ] } 如何从内置验证错误中删除第三方括号!请帮帮我。

class CustomerAdd(models.Model):
    user = models.ForeignKey('accounts.CustomUser', on_delete=models.CASCADE)
    is_customer = models.BooleanField('customer status', default=True)
    is_supplier = models.BooleanField('supplier status', default=False)
    customer_name = models.CharField(max_length=100)
    customer_phone = models.CharField(max_length=15, unique=True, error_messages={'unique': "This customer_phone has "
                                                                                            "already been registered."})
    previous_due = models.DecimalField(max_digits=10, decimal_places=2, default=0.00)
    date = models.DateField(auto_now_add=True)
    picture = models.ImageField(upload_to='customer_add_pics', default='images.png')

    def __str__(self):
        return self.customer_name

    class Meta:
        verbose_name = "Customer Add"
        verbose_name_plural = "Customer Add"

以下是API的回应:

{
    "customer_phone": [
        "This customer_phone has already been registered."
    ]
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129033
文章 [ 1 ]  |  最新文章 3 年前