문제

아래에 표시된 식당과 댓글 모델이 있습니다. 댓글 모델에는 외국에서 레스토랑이 있습니다. 레스토랑 인스턴스 목록을 반환하는 일부 레스토랑 필드와 주석 모델의 댓글 필드에서 검색을 수행하려면 어떻게해야합니까?

감사

class Restaurant(models.Model):

    name = models.CharField(max_length=100)
    country=models.ForeignKey(Country)
    city=models.ForeignKey(City)
    street=models.CharField(max_length=100)
    street_number=models.PositiveSmallIntegerField()
    postal_code=models.PositiveIntegerField(blank=True, null=True)
    slug = models.SlugField(unique=True)


class Comment(models.Model):

    user = models.ForeignKey(User)
    restaurant = models.ForeignKey(Restaurant)
    submit_date = models.DateTimeField(blank = True, null = False)
    comment = models.TextField() 
도움이 되었습니까?

해결책

매뉴얼을 읽어야한다고 생각합니다. http://django-haystack.readthedocs.org/en/latest/tutorial.html

multivalue를 찾으십시오.

class RestaurantIndex(indexes.SearchIndex): 
     comments = indexes.MultiValueField() 
     def prepare_comments(self, obj): 
         return [a for a in obj.comment_set.all()]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top