django - How to search one model only in Haystack -


i've got app 2 models, restaurant , dish. dish has foreign key restaurant. i'm trying build separate search forms using haystack, 1 people search restaurant.name , search dish.name.

i'm having trouble separating out , understanding how haystack this. since created both of indexes below, when have searchform, if type in "shrimp" in search box return "grilled shrimp", , if enter in "shakeshack" results return "shakeshack". goal have restaurant search form if type in "shrimp" shouldn't getting results because there no restaurants "shrimp" in name. right form seems allowing searching both models.

my indices:

class restaurantindex(indexes.searchindex, indexes.indexable):     text = indexes.charfield(document=true, use_template=true)      def get_model(self):         return restaurant   class dishindex(indexes.searchindex, indexes.indexable):     text = indexes.charfield(document=true, use_template=true)      def get_model(self):         return dish 

my search form:

class mysearchform(searchform):     def search(self):         sqs = super(mysearchform, self).search()              if not self.is_valid():                 return self.no_query_found()          return sqs 

i've tried inserting sqs.models(restaurant) limit search/return results restaurant model it's not working. i've tried putting in url conf: searchview(searchqueryset=searchqueryset().models(restaurant)

any appreciated!

thanks! yin

update: i've tried hedde's suggestion, still getting results both restaurant , dish:

class citysearchform(searchform):     models = [restaurant]      def get_models(self):        return self.models      def search(self):         # first, store searchqueryset received other processing.          sqs = super(citysearchform, self).search().models(restaurant)          if not self.is_valid():             return self.no_query_found()         return sqs 

also tried substituting modelsearchform searchform gives me couple checkboxes in form restaurant , dish don't seem affect search results no matter whether checked or not.

see haystack's builtin modelsearchform, should work:

class modelsearchform(searchform):     models = [         restaurant     ]      def get_models(self):         return self.models      def search(self):         sqs = super(mysearchform, self).search().models(*self.get_models())         return sqs 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -