So I've used django rest framework to serialize my data to make api calls. Great, that all worked well. Now I wanted to implement a search and return the serialized data in JSON format like I do with normal data. I feel like I followed the drf-haystack basic usage guide( https://drf-haystack.readthedocs.org/en/latest/basic_usage.html) correctly to get started. But I'm not getting any results when I make a call to the url. So, I'm going to use this event app. I want to be able to search through the titles. i.e( "party downtown")
So here's what I'm working with. Model: class Event(models.Model): business = models.ForeignKey(Business) title = models.CharField(max_length=75) event_date = models.DateField(blank=True,default=datetime.date.today) startTime = models.DateTimeField(blank=True,default=datetime.datetime. now) endTime = models.DateTimeField(blank=True,null=True) description = models.TextField(blank=True) search_indexes.py: class EventIndex(indexes.SearchIndex,indexes.Indexable): text = indexes.CharField(document=True,use_template=True) title = indexes.CharField(model_attr="title") description = indexes.CharField(model_attr="description") )) def get_model(self): return Event def index_queryset(self,using=None): return self.get_model().objects.all() Serializer(EventSearchSerializer): class EventSearchSerializer(HaystackSerializer): class Meta: # The `index_classes` attribute is a list of which search indexes # we want to include in the search. index_classes = [EventIndex] # The `fields` contains all the fields we want to include. # NOTE: Make sure you don't confuse these with model attributes. These # fields belong to the search index! fields = [ "text", "title", "description" ] Views: ( I've tried both ways mentioned in the docs. With viewsets and without): class EventSearchView(HaystackViewSet): # `index_models` is an optional list of which models you would like to include # in the search result. You might have several models indexed, and this provides # a way to filter out those of no interest for this particular view. # (Translates to `SearchQuerySet().models(*index_models)` behind the scenes. index_models = [Event] serializer_class = EventSearchSerializer class EventSearchView2(ListModelMixin, HaystackGenericAPIView): serializer_class = EventSearchSerializer def get(self,request, *args,**kwargs): return self.list(request,*args,**kwargs) Urls: router = routers.DefaultRouter() router.register("event/search", EventSearchView, base_name="event-search") urlpatterns = [ # api url for User to Create, Read, View url(r'^~api/v1/', include(router.urls)), url( regex=r'^~api/v2/search/$', view = views.EventSearchView2.as_view(), name="event_search_api" ),] I perform a search in the url: url: http://localhost/events/~api/v2/search/?title=club and I get nothing,but there's data there for sure with that title. I get a 200 OK code back. But 0 results I'm trying to figure this out, but I got nothing so far. Thanks for reading this far. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/450186a9-2b7f-4dc9-9803-aa156d669f21%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.