1
我有一個queryset的extra()方法的問題。Django模型過濾器()和額外的()
所以,我找回我的對象有:
invoices = Invoice.objects.select_related().filter(quantity__gt=0,begin__gte=values['start_day'],end__lte=values['end_day'])
所以它的工作原理,我有我的發票。 之後,我使用其他時間過濾器():
invoices = invoices.filter(max__gte=duration)
它也能工作。 但是,之後,我需要因爲我的請求,使用額外的(),所以我有:
cond = 'discount="YES" AND priceeuro*(%d%%fixe)<=%d'
invoices = invoices.extra(where=[cond],params=[duration,price])
那麼,它的工作原理,但我的發票變量包含多個元素之前。 這就像兩個過濾器()沒有使用。
如果你知道爲什麼,
謝謝。
編輯:
這是與查詢相關的SQL:
WHERE
("invoice"."product_id" IN (
SELECT U0."id"
FROM "product" U0
WHERE U0."accommodation_id" IN (
SELECT U0."id"
FROM "accommodation" U0
WHERE U0."resort_id" IN (
SELECT U0."id"
FROM "resort" U0
WHERE U0."area_id" IN (
SELECT U0."id"
FROM "area" U0
WHERE U0."country_id" = 9
))))
AND "invoice"."quantity" > 0
AND "invoice"."end" <= 2010-12-31
AND "invoice"."begin" >= 2010-12-01
AND fixe % 7 = 0
AND (discount="YES" AND pricediscountincludedeuro*(7% fixe)<=250)OR(discount="NO" AND priceeuro*(7% fixe)<=250))