0

私は現在、djangoでページを作成しています。このページには、4つのフォームフィールド、2つのテキスト、2つの選択フィールドがあり、送信されると、それらのフィールドを取得して、一致するアイテムをいくつかのモデルで検索します。

モデルは次のようになります。

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フィールド、last_nameフィールド、国籍フィールド、およびexperienceフィールドを検索しようとしていますが、first_nameフィールドが空白の場合、すべての行を返すように空の値を渡す必要があり、そこからフィルターをかけます。姓も同じですが、どういうわけか私にはまったく機能していません。これは私のsqsです:

results = SearchQuerySet().models(Person).filter(first_name=sname, last_name=slastname, nationality=scountry, experience__pk=sexperience)

何か案は?

4

1 に答える 1

0

特定のエラーやスタック トレースを確認しないと、何が「まったく機能していない」のかを判断するのは困難です。

編集:提供されたビュー コードを見て、フィルターを削除し、Fighter、Referee、Insider、および Judge モデルのすべてのオブジェクトを返します。これは、ここでの問題がフィルターにあり、他の何かではないことを確認するためです。

次に、オブジェクトが結果に配置されていることを確認したら、フィルターを 1 つずつ挿入して、問題のあるフィルターを特定します。これを試して、結果を返信してください。

于 2012-05-14T15:16:22.263 に答える