简体   繁体   English

Django(1.9)Watson索引Django Tagging TagField

[英]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? 如何索引由Django标记 (v0.4.5)TagField管理器管理的字段?

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. 标签全部正常工作, Watson (v1.2.1)正在对模型建立索引,并从搜索char和text字段中返回结果,但应该这样做,但是如果搜索词是标签,则不会。

The registering is done in an AppConfig as documented: 按照记录在AppConfig中完成注册:

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: 并且具有tag TagField字段的Team模型都很好:

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? 任何人都知道如何获取与char或text字段相同的字段索引吗?

Thanks so much Rich 非常感谢Rich

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. 最后,我删除了Django Tagging,仅使用日期和名称字符串创建了自己的“标签”模型,然后在每个要标记的模型中添加了ManyToMany字段。 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. 需要一些额外的逻辑来更新标签池,但这似乎很容易,只需循环即可在保存关联模型时测试tag.name.exists()。

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. 具有这种简单的字段类型也使Django Material表单易于为静态标签池添加选择器,因此双赢。

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. 我仍然想知道是否有人可以通过模型管理器返回文本,因为我只学习了python和django开/关了几个月,并且真的很喜欢它,所以想做一些适当的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM