我的模型:
class UserInfo(models.Model):
UserFirstName = models.CharField(max_length=128, validators=[name_regex])
UserMiddleName = models.CharField(max_length=128, validators=[name_regex])
UserLastName = models.CharField(max_length=128, validators=[name_regex])
UserFullName = models.CharField(max_length=128, validators=[name_regex])
我的序列化器:
class UserInfoNameSerializer(serializers.ModelSerializer):
class Meta:
model = UserInfo
fields = ('UserFirstName', 'UserMiddleName', 'UserLastName', 'UserFullName')
read_only_fields = ['UserFullName']
我想要从User UserFirstName,UserMiddleName和UserLastName创建的字段UserFullName。
我尝试过但失败了
@property
def UserFullName(self):
return self.UserFirstName + " " + self.UserMiddleName + " " + self.UserLastName
请帮帮我!