当api中发生多个帖子时,在用户的电子邮件中显示验证错误,我该如何解决?

时间:2018-10-18 11:13:58

标签: django-rest-framework

在序列化器中:

class EventUserRegisterSerializer(ModelSerializer):
   first_name = serializers.CharField(write_only=True)
   last_name = serializers.CharField(write_only=True)
   email = serializers.EmailField(validators= 
   [UniqueValidator(queryset=User.objects.all())], write_only=True)

观看次数:

  try:
        user = User.objects.get(phone_number=phone_number, 
        email=email)
        user.first_name = first_name
        user.last_name = last_name

  except User.DoesNotExist:

       user = 
          User.objects.create(username=username,first_name=first_name, 
          last_name=last_name, phone_number=phone_number,
                                    email=email)

型号:

class User(AbstractUser):
    first_name = models.CharField(max_length=200, blank=True, 
    default="")
    last_name = models.CharField(max_length=200, blank=True, 
    default="")
    phone_number = models.CharField(max_length=20, unique=True, 
    default="")
    timestamp = UnixDateTimeField(auto_now=True)

    @property
    def unique_id(self):
         return self.first_name + self.timestamp

我有一个部分付款系统,所以我必须做多个“过帐”,但是会发生验证错误

0 个答案:

没有答案