def test_deconstruction(self): constraint = models.Q(price__gt=models.F('discounted_price')) name = 'price_gt_discounted_price' check = models.CheckConstraint(constraint, name) path, args, kwargs = check.deconstruct() self.assertEqual(path, 'djmodels.db.models.CheckConstraint') self.assertEqual(args, ()) self.assertEqual(kwargs, {'constraint': constraint, 'name': name})
def test_repr(self): constraint = models.Q(price__gt=models.F('discounted_price')) name = 'price_gt_discounted_price' check = models.CheckConstraint(constraint, name) self.assertEqual( repr(check), "<CheckConstraint: constraint='{}' name='{}'>".format( constraint, name), )
class Meta: constraints = [ models.CheckConstraint( models.Q(price__gt=models.F('discounted_price')), 'price_gt_discounted_price') ]
class Meta: constraints = [ models.CheckConstraint(models.Q(age__gte=18), 'is_adult') ]
def today_callable_q(): return models.Q(last_action__gte=datetime.datetime.today())
def get_extra_descriptor_filter(self, instance): return models.Q(lang=get_language())