質問編集履歴
2
name 'Response' is not definedは解決したのですが、新たにエラーが出てしまいました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,12 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
+
【serializers.pyを変更後(こちらの解決方法の提示をよろしくおねがいします。)】
|
38
|
+
|
39
|
+
Could not resolve URL for hyperlinked relationship using view name "post-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
|
40
|
+
|
41
|
+
|
42
|
+
|
37
43
|
どうやらapi/views.py のPostView内で発生しているようです。
|
38
44
|
|
39
45
|
公式のdjango rest frameworkのサイトを見る限り、Responseはimportせずとも使えるようですが、エラーが出てしまいます。
|
@@ -290,6 +296,14 @@
|
|
290
296
|
|
291
297
|
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
292
298
|
|
299
|
+
posts = serializers.HyperlinkedRelatedField(
|
300
|
+
|
301
|
+
many=True, read_only=True, view_name="post-detail", lookup_url_kwarg="post_id"
|
302
|
+
|
303
|
+
)
|
304
|
+
|
305
|
+
|
306
|
+
|
293
307
|
class Meta:
|
294
308
|
|
295
309
|
model = User
|
@@ -308,6 +322,10 @@
|
|
308
322
|
|
309
323
|
)
|
310
324
|
|
325
|
+
read_only_fields = "posts"
|
326
|
+
|
327
|
+
|
328
|
+
|
311
329
|
|
312
330
|
|
313
331
|
class FriendSerializer(serializers.HyperlinkedModelSerializer):
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,34 +130,6 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
-
# def list(self, request, user_pk=None):
|
134
|
-
|
135
|
-
# try:
|
136
|
-
|
137
|
-
# posts = get_list_or_404(self.queryset, author=user_pk)
|
138
|
-
|
139
|
-
# except (TypeError, ValueError):
|
140
|
-
|
141
|
-
# raise Http404
|
142
|
-
|
143
|
-
# else:
|
144
|
-
|
145
|
-
# serializer = self.get_serializer(posts, many=True)
|
146
|
-
|
147
|
-
# return Response(serializer.data)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
# def retrieve(self, request, pk=None, user_pk=None):
|
152
|
-
|
153
|
-
# post = get_object_or_404(self.queryset, pk=pk, author=user_pk)
|
154
|
-
|
155
|
-
# serializer = self.get_serializer(post)
|
156
|
-
|
157
|
-
# return Response(serializer.data)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
133
|
```
|
162
134
|
|
163
135
|
|