From f14f4506f78ba91e2f84b1c2dface0c50c1f27d7 Mon Sep 17 00:00:00 2001 From: Kunal Patil Date: Sat, 8 Oct 2022 22:25:46 -0400 Subject: [PATCH 1/2] added apartments search functionality --- housing/urls.py | 4 +++- housing/views.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/housing/urls.py b/housing/urls.py index 7e399e4a..73e69690 100644 --- a/housing/urls.py +++ b/housing/urls.py @@ -8,7 +8,7 @@ # router.register(r'flats', views.FlatViewSet, basename="flat_viewset") # router.register(r'owners', views.OwnerViewSet, basename="owner_viewset") # router.register(r'interests', views.InterestedViewSet, basename="interests_viewset") -router.register(r'apartments', views.ApartmentViewSet, basename="apartment_viewset") +# router.register(r'apartments', views.ApartmentViewSet, basename="apartment_viewset") # router.register(r'lease', views.LeaseViewSet, basename='lease_viewset') urlpatterns = [ @@ -21,5 +21,7 @@ path('lease/', views.LeaseViewSet.as_view()), path('interests', views.InterestedViewSet.as_view()), path('interests/', views.InterestedViewSet.as_view()), + path('apartments', views.ApartmentViewSet.as_view()), + path('owners/', views.ApartmentViewSet.as_view()), ] \ No newline at end of file diff --git a/housing/views.py b/housing/views.py index 13123796..cafd81c4 100644 --- a/housing/views.py +++ b/housing/views.py @@ -38,6 +38,8 @@ class LeaseViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPI class ApartmentViewSet(viewsets.ModelViewSet): + search_fields = ['address', 'facilities', 'owner_id'] + filter_backends = (filters.SearchFilter,) queryset = models.Apartment.objects.all() serializer_class = serializers.ApartmentSerializer From dddda46bfc164e7aad2d6cc5f57debdb0c7bfad5 Mon Sep 17 00:00:00 2001 From: Kunal Patil Date: Sat, 8 Oct 2022 22:46:21 -0400 Subject: [PATCH 2/2] updated apartments search functionality --- housing/tests.py | 1 + housing/urls.py | 4 ++-- housing/views.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/housing/tests.py b/housing/tests.py index da6ca72a..efbd06be 100644 --- a/housing/tests.py +++ b/housing/tests.py @@ -51,3 +51,4 @@ def test_delete_owner(self): response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(Owner.objects.count(), 0) + diff --git a/housing/urls.py b/housing/urls.py index 73e69690..f14fdd84 100644 --- a/housing/urls.py +++ b/housing/urls.py @@ -22,6 +22,6 @@ path('interests', views.InterestedViewSet.as_view()), path('interests/', views.InterestedViewSet.as_view()), path('apartments', views.ApartmentViewSet.as_view()), - path('owners/', views.ApartmentViewSet.as_view()), - + path('apartments/', views.ApartmentViewSet.as_view()), + ] \ No newline at end of file diff --git a/housing/views.py b/housing/views.py index cafd81c4..14e4f445 100644 --- a/housing/views.py +++ b/housing/views.py @@ -37,7 +37,7 @@ class LeaseViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPI serializer_class = serializers.LeaseSerializer -class ApartmentViewSet(viewsets.ModelViewSet): +class ApartmentViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPIView): search_fields = ['address', 'facilities', 'owner_id'] filter_backends = (filters.SearchFilter,) queryset = models.Apartment.objects.all()