def test_valid_api_works(self): Order(price=100).save() # valid api self.assertIsInstance(Order.objects.cost_between(lower=50), models.QuerySet) self.assertIsInstance(OrderQuerySet.cost_between.q(lower=50), models.Q) q1 = OrderQuerySet.cost_between.q(lower=50) q2 = OrderQuerySet.cost_between.q(upper=200000) Pizza.objects.filter(nested_q('order', q1 & q2)) # invalid api with self.assertRaisesRegexp(Exception, 'Not a Q object'): Pizza.objects.filter(nested_q('order', Order.objects.cost_between(0, 500))) # invalid api with self.assertRaisesRegexp(AttributeError, 'no attribute'): q2 = Order.objects.cost_between.q(upper=200000)
def test_valid_api_works(self): Order(price=100).save() # valid api self.assertIsInstance(Order.objects.cost_between(lower=50), models.QuerySet) self.assertIsInstance(OrderQuerySet.cost_between.q(lower=50), models.Q) q1 = OrderQuerySet.cost_between.q(lower=50) q2 = OrderQuerySet.cost_between.q(upper=200000) Pizza.objects.filter(nested_q('order', q1 & q2)) # invalid api with self.assertRaisesRegexp(Exception, 'Not a Q object'): Pizza.objects.filter( nested_q('order', Order.objects.cost_between(0, 500))) # invalid api with self.assertRaisesRegexp(AttributeError, 'no attribute'): q2 = Order.objects.cost_between.q(upper=200000)
def delivered_in_last_x_days(self, days): return nested_q('order', OrderQuerySet.delivered_in_last_x_days.q(days))
def is_delivered(self): return nested_q('order', OrderQuerySet.is_delivered.q())
def delivered_in_last_x_days(cls, days): return nested_q('order', OrderQuerySet.delivered_in_last_x_days(days))
def is_delivered(cls): return nested_q('order', OrderQuerySet.is_delivered())