Skip to content
This repository was archived by the owner on Aug 8, 2020. It is now read-only.

Commit 1cbf793

Browse files
authored
Update README.md
1 parent 07c84f1 commit 1cbf793

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
2+
CheckConstraint now accepts any boolean expression since [Django 3.1+](https://docs.djangoproject.com/en/3.1/ref/models/constraints/#check) so this particular one can be expressed using RawSQL.
3+
4+
```python
5+
CheckConstraint(
6+
check=RawSQL(
7+
'non_null_count(amount::integer , amount_off::integer, percentage::integer) = 1',
8+
output_field=models.BooleanField(),
9+
)
10+
)
11+
```
12+
13+
14+
Or event Func, Cast, and Exact.
15+
16+
```python
17+
non_null_count = Func(Cast('amount', models.IntegerField()), Cast('amount_off', models.IntegerField()), Cast('percentage', models.IntegerField()), function='non_null_count')
18+
19+
CheckConstraint(
20+
check=Exact(non_null_count, 1),
21+
)
22+
```
23+
24+
25+
26+
27+
----
28+
29+
130
| PyPI | Python | Django | [LICENSE](./LICENSE) |
231
|:------------------------------:|:---------:|:-------:|:--------------------:|
332
|[![PyPI version](https://badge.fury.io/py/django-check-constraint.svg)](https://badge.fury.io/py/django-check-constraint) | [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-check-constraint.svg)](https://pypi.org/project/django-check-constraint) | [![PyPI - Django Version](https://img.shields.io/pypi/djversions/django-check-constraint.svg)](https://docs.djangoproject.com/en/2.2/releases/) | [![PyPI - License](https://img.shields.io/pypi/l/django-check-constraint.svg)](https://github.com/jackton1/django-check-constraint/blob/master/LICENSE) |

0 commit comments

Comments
 (0)