我有一个查询集,表现得有些奇怪。当我单独运行self.get()
部分并打印结果(即pr
)时,它会正确返回PriceRange对象。当我返回相同的值时,它是无。
class PriceRangeQuerySet(QuerySet):
def get_price_range(self, price):
try:
pr = self.get(
(Q(bottom__isnull = True) | Q(bottom__lt = price)) & \
(Q(top__isnull = True) | Q(top__gte = price))
)
return pr
except PriceRange.DoesNotExist:
mail_admins("Price range not found", 'Price: %d' % price)
except PriceRange.MultipleObjectsReturned:
mail_admins("Multiple matching price ranges found", 'Price: %d' % price)