Search Results

73 views
Skip to first unread message

Na Peters

unread,
Sep 21, 2015, 11:43:54 AM9/21/15
to django-watson discussion group
Hello All,
I am new to programming so apologize if this is an incredibly stupid question, but I have installed watson to my project however the search results are not displaying quite like I thought they would.

I have two models, a manufacturer and supplier. The manufacturer has just mfr name and part number. This mfr part number can be associated with many different supplier numbers as many suppliers use their own numbers to represent the mfr number. So I would like the search results to display all the suppliers information that carry that mfr part number, whether the user searches the mfr part or a given supplier number. 

However that does not happen, if I type in the mfr number just one result is displayed which is the mfr number. If I type a supplier number only that specific supplier number is displayed. How do I set it up so if I search on either supplier or mfr number all the associated supplier numbers grouped to that one mfr number is displayed in the results? Is there a setting in Watson I need to adjust, or do I have my models setup incorrectly? Thanks in advance for any help.

Here is how I set up the models:

from django.db import models

class Parts(models.Model):
mfr_name = models.CharField(max_length=200, null=True)
mfr_part = models.CharField(max_length=30, null=True)

def __unicode__(self):
return self.mfr_part


class Supplier(models.Model):
sup_name = models.CharField(max_length=50)
sup_part = models.CharField(max_length=30)
part_desc = models.CharField(max_length=200)
part_price = models.CharField(max_length=6, null=True)
my_price = models.CharField(max_length=6, null=True)
part_qty = models.IntegerField(null=True)
part_img = models.ImageField(upload_to=None, height_field=None, width_field=None, max_length=400, null=True)
url = models.URLField()
Parts = models.ForeignKey('Parts')

def __unicode__(self):
return self.sup_part

Dave Hall

unread,
Sep 21, 2015, 4:00:37 PM9/21/15
to django-watson discussion group
Register the parts model, something like this:

watson.register(Part, fields=["mfr_name", "mfr_part", "supplier_set__sup_name", "supplier_set__sup_part"])

You'll need to list in the other supplier fields you want to index.

This way, only Part models will be returned in the results, but they will be matched based on fields on themselves and associated Suppliers.
--
You received this message because you are subscribed to the Google Groups "django-watson discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-watso...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-watson.
For more options, visit https://groups.google.com/d/optout.

Na Peters

unread,
Sep 21, 2015, 11:05:41 PM9/21/15
to django-watson discussion group
Hello Dave,
Thanks for the response. So I added your suggestion but same results are being displayed. Did I do it right?

from django.apps import AppConfig
import watson

class MySiteConfig(AppConfig):
name = "mysite"
def ready(self):
Parts = self.get_model("Parts")
watson.register(Parts, fields=["mfr_name", "mfr_part", "supplier_set_sup_name", "supplier_set_sup_part"])
def ready(self):
Supplier = self.get_model("Supplier")
watson.register(Supplier)

Dave Hall

unread,
Sep 22, 2015, 4:18:13 AM9/22/15
to django-watson discussion group
Don't register the supplier model. Just the parts model. Otherwise, looks good!
--

Na Peters

unread,
Sep 22, 2015, 10:20:15 PM9/22/15
to django...@googlegroups.com
Hi Dave sorry to keep bugging you but when I remove the Supplier part, no search results work. When I add the Supplier part back but without the 'watson.register...' line I get the same results I was getting previously. I tried doing the reverse and completely removed the Parts register and kept supplier but would get the same results I was getting before. Have any other ideas I can try? Just FYI I have not reviewed the section on 'searching for models' is there a step in there that I need to be doing? Again sorry for keeping asking, I am just running out of options to try in order to get this to work. 

--
You received this message because you are subscribed to a topic in the Google Groups "django-watson discussion group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-watson/-hG1H6J37pA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-watso...@googlegroups.com.

Dave Hall

unread,
Sep 23, 2015, 4:03:59 AM9/23/15
to django...@googlegroups.com
You need to run buildwatson whenever you make changes to the register code.

I'd definitely read all the documentation, though. It's only a few pages, and might show something obvious you're missing.
Reply all
Reply to author
Forward
0 new messages