Search code examples
djangosearchindexingdjango-taggingdjango-watson

Django (1.9) Watson index Django Tagging TagField


How can I index a field that is managed by the Django Tagging (v0.4.5) TagField manager?

The tags are all working correctly and Watson (v1.2.1) is indexing the models and returning results from searching the char and text fields as it should but not if the search term is a tag.

The registering is done in an AppConfig as documented:

from __future__ import unicode_literals
from django.apps import AppConfig
from watson import search as watson

class TeamConfig(AppConfig):
    name = 'team'
    def ready(self):
        Team = self.get_model("Team")
        watson.register(Team, fields=("title_text", "tagline", "description", "tags"))
        Member = self.get_model("Member")
        watson.register(Member)

and the Team model that has the tag TagField field is all good:

import blahs
...
from watson import search as watson
from tagging.fields import TagField
...

class Team(models.Model):
    pub_date = models.DateField('date published', auto_now_add=True)
    title_text = models.CharField('Name', max_length=200, blank=False,
    ...
    tags = TagField()
    is_active = models.BooleanField('Active?', default=True)

Anyone got any idea how to get the field indexing same as a char or text field please?

Thanks so much Rich


Solution

  • In the end I ripped out Django Tagging, created my own model of 'tags' simply with a date and a name string and then threw a ManyToMany field in each of the models to be tagged. Needs some extra logic to update that pool of tags but that seems easy enough with a loop to test if tag.name.exists() upon save for the associated models.

    Having that simple field type also made Django Material form way easy to add a selector for the static pool of tags too so win win.

    Would still like to know if anyone has a way of returning text through a model manager as I've only been learning python and django on/off for a few months and really loving it so want to do things proper like.