始终序列化程序无效

时间:2017-01-30 08:18:29

标签: python django python-2.7

models.py

class Profile(models.Model):
   firstname = models.CharField(max_length=100,null=True,blank=True)
   lastname = models.CharField(max_length=100,null=True,blank=True)
   city = models.CharField(max_length=100,null=True,blank=True)
   state = models.CharField(max_length=100,null=True,blank=True)
   # . . . other fields

views.py

profile = Profile.objects.get(id=1)

serializer = LenderProfileSerializer(profile, data=request.data)

if serializer.is_valid():
     serializer.save()

serializers.py

class LenderProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = Profile

        fields = [
            'firstname',
            'lastname',
            'city',
            'state'
          ]

这是我的代码。例如,我正在尝试仅填充某些字段,因此我提供serializer = LenderProfileSerializer(profile, data=request.data)仍然无效。

0 个答案:

没有答案