#31646: Support annotated check constraints.
-------------------------------------+-------------------------------------
Reporter: Tonye Jack | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: check-constraints, | Triage Stage:
model constraints | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* status: new => closed
* needs_docs: 1 => 0
* resolution: => wontfix
* needs_tests: 1 => 0
* easy: 1 => 0
Comment:
`CheckConstraint` accepts any boolean expression since Django 3.1+ so this
particular one can be expressed using `RawSQL`
{{{#!python
CheckConstraint(
check=RawSQL(
'non_null_count(amount::integer , amount_off::integer,
percentage::integer) = 1',
output_field=models.BooleanField(),
)
)
}}}
Or event `Func`, `Cast`, and `Exact`.
{{{#!python
non_null_count = Func(Cast('amount', models.IntegerField()),
Cast('amount_off', models.IntegerField()), Cast('percentage',
models.IntegerField()), function='non_null_count')
CheckConstraint(
check=Exact(non_null_count, 1),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31646#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.b115eb983dfb7086c593640741673534%40djangoproject.com.