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
profile = Profile.objects.get(id=1)
serializer = LenderProfileSerializer(profile, data=request.data)
if serializer.is_valid():
serializer.save()
class LenderProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = [
'firstname',
'lastname',
'city',
'state'
]
这是我的代码。例如,我正在尝试仅填充某些字段,因此我提供serializer = LenderProfileSerializer(profile, data=request.data)
仍然无效。