union favorites create/destroy in one endpoint

This commit is contained in:
Anatoly 2019-09-09 10:47:38 +03:00
parent 0f6786fb13
commit 7577ad330c
2 changed files with 3 additions and 8 deletions

View File

@ -13,6 +13,5 @@ urlpatterns = [
name='create-comment'),
path('<int:pk>/comment/<int:comment_id>/', views.EstablishmentCommentRUDView.as_view(),
name='rud-comment'),
path('<int:pk>/favorites/add/', views.EstablishmentFavoritesCreateView.as_view()),
path('<int:pk>/favorites/delete/', views.EstablishmentFavoritesDestroyView.as_view()),
path('<int:pk>/favorites/', views.EstablishmentFavoritesCreateDestroyView.as_view()),
]

View File

@ -79,14 +79,10 @@ class EstablishmentCommentRUDView(generics.RetrieveUpdateDestroyAPIView):
return comment_obj
class EstablishmentFavoritesCreateView(generics.CreateAPIView):
"""View for adding establishment to favorites."""
class EstablishmentFavoritesCreateDestroyView(generics.CreateAPIView, generics.DestroyAPIView):
"""View for create/destroy establishment from favorites."""
serializer_class = serializers.EstablishmentFavoritesCreateSerializer
class EstablishmentFavoritesDestroyView(generics.DestroyAPIView):
"""View for destroy establishment from favorites."""
def get_object(self):
"""
Returns the object the view is displaying.