diff --git a/housing/urls.py b/housing/urls.py index f14fdd84..7cae4121 100644 --- a/housing/urls.py +++ b/housing/urls.py @@ -4,13 +4,14 @@ router = DefaultRouter() -router.register(r'users', views.UserViewSet, basename="user_viewset") +# router.register(r'users', views.UserViewSet, basename="user_viewset") # 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'lease', views.LeaseViewSet, basename='lease_viewset') + urlpatterns = [ path('', include(router.urls)), path('owners', views.OwnerViewSet.as_view()), @@ -23,5 +24,8 @@ path('interests/', views.InterestedViewSet.as_view()), path('apartments', views.ApartmentViewSet.as_view()), path('apartments/', views.ApartmentViewSet.as_view()), + path('users', views.UserViewSet.as_view()), + path('users/', views.UserViewSet.as_view()), + ] \ No newline at end of file diff --git a/housing/views.py b/housing/views.py index 14e4f445..36189476 100644 --- a/housing/views.py +++ b/housing/views.py @@ -5,10 +5,14 @@ # Create your views here. -class UserViewSet(viewsets.ModelViewSet): +class UserViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPIView): """ This viewset automatically provides `list` and `retrieve` actions. """ + +# Add search fields to the user view set + search_fields = ['contact_email', 'contact_number'] + filter_backends = (filters.SearchFilter,) queryset = models.User.objects.all() serializer_class = serializers.UserSerializer @@ -38,6 +42,7 @@ class LeaseViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPI class ApartmentViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPIView): + search_fields = ['address', 'facilities', 'owner_id'] filter_backends = (filters.SearchFilter,) queryset = models.Apartment.objects.all()