File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
graphene_django/rest_framework Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ def fields_for_serializer(
2626 exclude_fields ,
2727 is_input = False ,
2828 convert_choices_to_enum = True ,
29+ lookup_field = None ,
2930):
3031 fields = OrderedDict ()
3132 for name , field in serializer .fields .items ():
@@ -35,7 +36,9 @@ def fields_for_serializer(
3536 name in exclude_fields ,
3637 field .write_only
3738 and not is_input , # don't show write_only fields in Query
38- field .read_only and is_input , # don't show read_only fields in Input
39+ field .read_only
40+ and is_input
41+ and lookup_field != name , # don't show read_only fields in Input
3942 ]
4043 )
4144
@@ -91,13 +94,15 @@ def __init_subclass_with_meta__(
9194 exclude_fields ,
9295 is_input = True ,
9396 convert_choices_to_enum = convert_choices_to_enum ,
97+ lookup_field = lookup_field ,
9498 )
9599 output_fields = fields_for_serializer (
96100 serializer ,
97101 only_fields ,
98102 exclude_fields ,
99103 is_input = False ,
100104 convert_choices_to_enum = convert_choices_to_enum ,
105+ lookup_field = lookup_field ,
101106 )
102107
103108 if not _meta :
Original file line number Diff line number Diff line change @@ -143,17 +143,20 @@ class Meta:
143143
144144def test_read_only_fields ():
145145 class ReadOnlyFieldModelSerializer (serializers .ModelSerializer ):
146+ id = serializers .CharField (read_only = True )
146147 cool_name = serializers .CharField (read_only = True )
147148
148149 class Meta :
149150 model = MyFakeModelWithPassword
150- fields = ["cool_name" , "password" ]
151+ lookup_field = "id"
152+ fields = ["id" , "cool_name" , "password" ]
151153
152154 class MyMutation (SerializerMutation ):
153155 class Meta :
154156 serializer_class = ReadOnlyFieldModelSerializer
155157
156158 assert "password" in MyMutation .Input ._meta .fields
159+ assert "id" in MyMutation .Input ._meta .fields
157160 assert (
158161 "cool_name" not in MyMutation .Input ._meta .fields
159162 ), "'cool_name' is read_only field and shouldn't be on arguments"
You can’t perform that action at this time.
0 commit comments