Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf221b73

Browse files
Merge pull request#2197 from mtschammer/mtschammer-validated_attrs-rename
Renamed validated_attrs to validated_data to be more in line with other code
2 parents66bce38 +ab25d70 commitf221b73

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

‎docs/tutorial/1-serialization.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,21 @@ The first thing we need to get started on our Web API is to provide a way of ser
110110
style = serializers.ChoiceField(choices=STYLE_CHOICES,
111111
default='friendly')
112112

113-
def create(self,validated_attrs):
113+
def create(self,validated_data):
114114
"""
115115
Create and return a new `Snippet` instance, given the validated data.
116116
"""
117-
return Snippet.objects.create(**validated_attrs)
117+
return Snippet.objects.create(**validated_data)
118118

119-
def update(self, instance,validated_attrs):
119+
def update(self, instance,validated_data):
120120
"""
121121
Update and return an existing `Snippet` instance, given the validated data.
122122
"""
123-
instance.title =validated_attrs.get('title', instance.title)
124-
instance.code =validated_attrs.get('code', instance.code)
125-
instance.linenos =validated_attrs.get('linenos', instance.linenos)
126-
instance.language =validated_attrs.get('language', instance.language)
127-
instance.style =validated_attrs.get('style', instance.style)
123+
instance.title =validated_data.get('title', instance.title)
124+
instance.code =validated_data.get('code', instance.code)
125+
instance.linenos =validated_data.get('linenos', instance.linenos)
126+
instance.language =validated_data.get('language', instance.language)
127+
instance.style =validated_data.get('style', instance.style)
128128
instance.save()
129129
return instance
130130

‎rest_framework/serializers.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,20 @@ class ModelSerializer(Serializer):
608608
})
609609
_related_class=PrimaryKeyRelatedField
610610

611-
defcreate(self,validated_attrs):
611+
defcreate(self,validated_data):
612612
"""
613613
We have a bit of extra checking around this in order to provide
614614
descriptive messages when something goes wrong, but this method is
615615
essentially just:
616616
617-
return ExampleModel.objects.create(**validated_attrs)
617+
return ExampleModel.objects.create(**validated_data)
618618
619619
If there are many to many fields present on the instance then they
620620
cannot be set until the model is instantiated, in which case the
621621
implementation is like so:
622622
623-
example_relationship =validated_attrs.pop('example_relationship')
624-
instance = ExampleModel.objects.create(**validated_attrs)
623+
example_relationship =validated_data.pop('example_relationship')
624+
instance = ExampleModel.objects.create(**validated_data)
625625
instance.example_relationship = example_relationship
626626
return instance
627627
@@ -644,17 +644,17 @@ def create(self, validated_attrs):
644644

645645
ModelClass=self.Meta.model
646646

647-
# Remove many-to-many relationships fromvalidated_attrs.
647+
# Remove many-to-many relationships fromvalidated_data.
648648
# They are not valid arguments to the default `.create()` method,
649649
# as they require that the instance has already been saved.
650650
info=model_meta.get_field_info(ModelClass)
651651
many_to_many= {}
652652
forfield_name,relation_infoininfo.relations.items():
653-
ifrelation_info.to_manyand (field_nameinvalidated_attrs):
654-
many_to_many[field_name]=validated_attrs.pop(field_name)
653+
ifrelation_info.to_manyand (field_nameinvalidated_data):
654+
many_to_many[field_name]=validated_data.pop(field_name)
655655

656656
try:
657-
instance=ModelClass.objects.create(**validated_attrs)
657+
instance=ModelClass.objects.create(**validated_data)
658658
exceptTypeErrorasexc:
659659
msg= (
660660
'Got a `TypeError` when calling `%s.objects.create()`. '
@@ -679,7 +679,7 @@ def create(self, validated_attrs):
679679

680680
returninstance
681681

682-
defupdate(self,instance,validated_attrs):
682+
defupdate(self,instance,validated_data):
683683
assertnotany(
684684
isinstance(field,BaseSerializer)and (keyinvalidated_attrs)
685685
forkey,fieldinself.fields.items()
@@ -690,7 +690,7 @@ def update(self, instance, validated_attrs):
690690
(self.__class__.__module__,self.__class__.__name__)
691691
)
692692

693-
forattr,valueinvalidated_attrs.items():
693+
forattr,valueinvalidated_data.items():
694694
setattr(instance,attr,value)
695695
instance.save()
696696
returninstance

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp