0
我目前正在django中建立一個頁面,其中有4個表單域,2個文本,2個選擇域,當提交它時需要這些域並搜索多個模型以匹配項目。Haystack搜索多個字段
模型是這樣的:
class Person(models.Model):
user = models.ForeignKey(User, blank=True, null=True, verbose_name="the user associated with this profile")
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
about = models.TextField(max_length=255, blank=True, null=True)
birthdate = models.DateField(blank=True, null=True, verbose_name="Birthdate (yyyy-mm-dd)")
GENDER_CHOICES = (
(u'M', u'Male'),
(u'F', u'Female'),
)
gender = models.CharField(max_length=1, choices = GENDER_CHOICES, default = 'M')
picture = models.ImageField(upload_to='profile', blank=True, null=True)
nationality = CountryField(blank=True, null=True)
location = models.CharField(max_length=255, blank=True, null=True)
command_cert = models.BooleanField(verbose_name="COMMAND certification")
experience = models.ManyToManyField('userProfile.MartialArt', blank=True, null=True)
,我試圖搜索FIRST_NAME領域,姓氏場,國籍領域和經驗領域,但說如果FIRST_NAME字段爲空,我需要傳遞一個空值,以便返回所有行,然後用同樣的方法從那裏過濾掉,因爲某些原因,它對我來說根本不起作用。這是我的sqs:
results = SearchQuerySet().models(Person).filter(first_name=sname, last_name=slastname, nationality=scountry, experience__pk=sexperience)
有什麼想法嗎?
無論我在該領域使用什麼樣的條目組合,即使它們都是空白的,它也不會返回任何內容。 – flaiks
你能粘貼這個頁面的整個視圖嗎?有很多原因可能導致您的過濾器無法返回任何內容,但如果沒有更多信息,我無法開始排除故障。 – patrickn
這是整個視圖[鏈接](http://pastebin.com/rcST86Gw) – flaiks