I developed a filter system where it provides 3 options, such as property type, number of rooms and maximum price. Each time they select filter options, the user instantly receives a search result. For example, if the user has chosen the type of ownership of the apartment and the number of rooms as 4 and the maximum price of 12,000, then the user will receive those rents whose type of property is an apartment with 4 rooms of 12,000 marks. I developed the front end with React.js and was able to successfully get the user selected data. I also passed the data to ajax, but I do not know how to display the search results based on the filtered value provided by the user without loading the page.
Ajax Code
$.ajax({ type: 'GET', url: '/filter/space/', data{property:propertySelectedValue, room:roomSelectedValue, price:maxPrice}, success: function(data){ console.log(data['fields']); }, error: function(XMLHttpRequest, textStatus, errorThrown){ console.error("Status: " + textStatus); alert("Error: " + errorThrown); }, });
Views.py
class FilterSpace(View): def get(self,request,*args,**kwargs): property = request.GET.get('property',None) room = request.GET.get('room', None) price = request.GET.get('price', None) rental = Rental.objects.all() if room: rental = rental.filter(room=room) print('rental',rental) if price: rental = rental.filter(price__lte=price) if property: rental = rental.filter(property=property) rental_json = serializers.serialize('json',rental) print('rental_json',rental_json) return HttpResponse(rental_json,content_type="application/json")
javascript jquery python ajax django
milan
source share