LilyFoote/rest-framework-generic-relations

I need views.py and urls.py for demo

ctrngk opened this issue · 1 comments

I am relatively new to DRF. I am interested in post method to generic relations. However, I cannot make the second example work, which contains bookmark-detail and note-detail in one serializer.

My urls.py and views.py looks like a mess
path('bookmark/', views.BookmarkDetail.as_view(), name='bookmark-detail'),
path('note/', views.NoteDetail.as_view(), name='note-detail'),

class BookmarkDetail(generics.RetrieveAPIView):
serializer_class = TagSerializer
queryset = Bookmark.objects.all()

class NoteDetail(generics.RetrieveAPIView):
serializer_class = TagSerializer
queryset = Note.objects.all()

I literately do not know what I am doing. So I need some demos to understand generic relations with DRF.

# views.py
class BookmarkViewSet(viewsets.ModelViewSet):
        serializer_class = BookmarkSerializer
        queryset = Bookmark.objects.all()


class NoteViewSet(viewsets.ModelViewSet):
        serializer_class = NoteSerializer
        queryset = Note.objects.all()


class TagViewSet(viewsets.ModelViewSet):
        serializer_class = TagSerializer
        queryset = TaggedItem.objects.all()

#  urls.py
router.register('bookmark', views.BookmarkViewSet) # bookmark-detail included by default
router.register('note', views.NoteViewSet) # note-detail included by default
router.register('tag', views.TagViewSet)