File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1117,9 +1117,36 @@ def get_fields(self):
1117
1117
if source == '*' :
1118
1118
source = field_name
1119
1119
1120
+ # Get the right model and info for source with attributes
1121
+ source_attrs = source .split ('.' )
1122
+ source_info = info
1123
+ source_model = model
1124
+
1125
+ if len (source_attrs ) > 1 :
1126
+ attr_info = info
1127
+ attr_model = model
1128
+
1129
+ for attr in source_attrs [:- 1 ]:
1130
+ if attr not in attr_info .relations :
1131
+ break
1132
+
1133
+ attr_model = attr_info .relations [attr ].related_model
1134
+ attr_info = model_meta .get_field_info (attr_model )
1135
+ else :
1136
+ attr = source_attrs [- 1 ]
1137
+ if (
1138
+ attr in attr_info .fields_and_pk
1139
+ or attr in attr_info .relations
1140
+ or hasattr (attr_model , attr )
1141
+ or attr == self .url_field_name
1142
+ ):
1143
+ source = attr
1144
+ source_info = attr_info
1145
+ source_model = attr_model
1146
+
1120
1147
# Determine the serializer field class and keyword arguments.
1121
1148
field_class , field_kwargs = self .build_field (
1122
- source , info , model , depth
1149
+ source , source_info , source_model , depth
1123
1150
)
1124
1151
1125
1152
# Include any kwargs defined in `Meta.extra_kwargs`
You can’t perform that action at this time.
0 commit comments