Domanda

Ho il ristorante e i modelli di commento mostrati di seguito. Il modello di commento ha un ristorante straniero. Come posso eseguire una ricerca in alcuni campi del ristorante e nel campo dei commenti del modello di commento che restituisce un elenco di istanze del ristorante?

Grazie

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() 
È stato utile?

Soluzione

Penso che dovresti leggere il manuale: http://django-haystack.readthedocs.org/en/latest/tutorial.html

Cerca multivale:

class RestaurantIndex(indexes.SearchIndex): 
     comments = indexes.MultiValueField() 
     def prepare_comments(self, obj): 
         return [a for a in obj.comment_set.all()]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top