blu*_*air 2 python django django-haystack elasticsearch
运行rebuild_index时,来自其他应用程序的对象正在被索引,但在一个应用程序上发生SearchFieldError。
这是我的相关应用程序的 models.py :
class Doctor(models.Model):
SPECIALTY_CHOICES = (
('Pediatric Physiotherapist', 'Pediatric Physiotherapist')
)
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
doctorName = models.CharField(max_length=100)
doctorQual = models.CharField(max_length=500)
doctorSpecial = models.CharField(choices=SPECIALTY_CHOICES, default='', max_length=50)
doctorSummary = models.CharField(max_length=1000)
doctorLocation = models.CharField(max_length=100, default=' ', null=True, blank=True)
slug = models.SlugField(null=True, blank=True)
city = models.CharField(max_length = 100, null=True, blank=True)
def __str__(self):
return self.doctorName
# save method overridden to generate slug for each object
def save(self, *args, **kwargs):
self.slug = slugify(self.doctorName)
super(Doctor, self).save(*args, **kwargs)
def get_absolute_url(self):
return "/doctor/doc_detail_page/%i" % self.id
def get_summary(self):
return self.doctorSummary
class Meta:
permissions = (
("can_create", "yoyo"),
)
Run Code Online (Sandbox Code Playgroud)
我的 search_indexes.py 是:
from haystack import indexes
from .models import Doctor
class DoctorIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
doctorName = indexes.CharField(model_attr='doctorName')
doctorSummary = indexes.CharField(model_attr='doctorSummary')
doctorSpecial = indexes.CharField(model_attr='doctorSpecial', faceted=True)
doctorLocation = indexes.CharField(model_attr='doctorLocation',faceted=True)
content_auto_doc = indexes.EdgeNgramField(model_attr='doctorName') # this field is for auto complete
def get_model(self):
return Doctor
def index_queryset(self, using=None):
return self.get_model().objects.all()
Run Code Online (Sandbox Code Playgroud)
这些是版本:
我在这里做错了什么。请帮忙!!
尝试在模型中为您收到错误的属性添加 default=' ' 或者尝试为您在 DoctorIndex 中收到错误的属性添加 null=True 它不久前对我有用 例如
example_field = indexes.CharField(model_attr='example_field', null=True)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
876 次 |
最近记录: |