﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31646	Support annotated check constraints.	Tonye Jack	nobody	"With the current Implementation of [https://docs.djangoproject.com/en/2.2/ref/models/constraints/#checkconstraint] there's currently no documented support for using annotated fields directly in the check constraint definition.

Created a sample repo https://github.com/jackton1/django-check-constraint which describes more on the possible use case to enable more complex check constraint definition which can be used directly. 

Use Case.

UDF
{{{
CREATE OR REPLACE FUNCTION public.non_null_count(VARIADIC arg_array ANYARRAY)
  RETURNS BIGINT AS
  $$
    SELECT COUNT(x) FROM UNNEST($1) AS x
  $$ LANGUAGE SQL IMMUTABLE;

}}}
  

Expected SQL

{{{
ALTER TABLE app_name_test_modoel ADD CONSTRAINT app_name_test_model_optional_field_provided
    CHECK(non_null_count(amount::integer , amount_off::integer, percentage::integer) = 1);
}}}



"	New feature	closed	Database layer (models, ORM)	2.2	Normal	wontfix	check-constraints, model constraints		Unreviewed	0	0	0	0	0	0
