Skip to content

Commit

Permalink
Merge pull request #48 from subodh30/addition_search
Browse files Browse the repository at this point in the history
Addition search
  • Loading branch information
subodh30 authored Oct 9, 2022
2 parents 72c15df + 16b1b82 commit a8b79ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion housing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -23,5 +24,8 @@
path('interests/<str:pk>', views.InterestedViewSet.as_view()),
path('apartments', views.ApartmentViewSet.as_view()),
path('apartments/<str:pk>', views.ApartmentViewSet.as_view()),
path('users', views.UserViewSet.as_view()),
path('users/<str:pk>', views.UserViewSet.as_view()),


]
7 changes: 6 additions & 1 deletion housing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a8b79ba

Please sign in to comment.