معرفی شرکت ها


django-check-constraint-1.0.9


Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر

توضیحات

Extends django check constraint to support annotations.
ویژگی مقدار
سیستم عامل -
نام فایل django-check-constraint-1.0.9
نام django-check-constraint
نسخه کتابخانه 1.0.9
نگهدارنده ['Tonye Jack']
ایمیل نگهدارنده ['jtonye@ymail.com']
نویسنده Tonye Jack
ایمیل نویسنده jtonye@ymail.com
آدرس صفحه اصلی https://github.com/jackton1/django-check-constraint
آدرس اینترنتی https://pypi.org/project/django-check-constraint/
مجوز MIT/Apache-2.0
# django-check-constraint ![django check constraint test.](https://github.com/jackton1/django-check-constraint/workflows/django%20check%20constraint%20test./badge.svg?branch=master) [![PyPI version](https://badge.fury.io/py/django-check-constraint.svg)](https://badge.fury.io/py/django-check-constraint) [![PyPI - License](https://img.shields.io/pypi/l/django-check-constraint.svg)](https://github.com/jackton1/django-check-constraint/blob/master/LICENSE) [![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/) ![Upload Python Package](https://github.com/jackton1/django-check-constraint/workflows/Upload%20Python%20Package/badge.svg) ![Create New Release](https://github.com/jackton1/django-check-constraint/workflows/Create%20New%20Release/badge.svg) Extends [Django's Check](https://docs.djangoproject.com/en/3.0/ref/models/options/#constraints) constraint with support for UDF(User defined functions/db functions) and annotations. #### Installation ```bash $ pip install django-check-constraint ``` ADD `check_constraint` to list of *INSTALLED* *APPS*. ```python INSTALLED_APPS = [ ... "check_constraint", ... ] ``` #### Scenario: Suppose you have a database function that returns the counts of null values in `[i, ...n]`. ```postgresql 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; ``` #### Example: ```postgresql SELECT public.non_null_count(1, null, null); ``` #### Outputs: ```sql non_null_count ---------------- 1 (1 row) ``` Defining a check constraint with this function The equivalent of (PostgresSQL) ```postgresql 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); ``` ## Usage Converting this to django functions and annotated check contraints can be done using: `function.py` ```python from django.db.models import Func, SmallIntegerField, TextField from django.db.models.functions import Cast class NotNullCount(Func): function = 'non_null_count' def __init__(self, *expressions, **extra): filter_exp = [ Cast(exp, TextField()) for exp in expressions if isinstance(exp, str) ] if 'output_field' not in extra: extra['output_field'] = SmallIntegerField() if len(expressions) < 2: raise ValueError('NotNullCount must take at least two expressions') super().__init__(*filter_exp, **extra) ``` #### Creating annotated check constraints ```python from django.db import models from django.db.models import Q from check_constraint.models import AnnotatedCheckConstraint class TestModel(models.Model): amount = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True) amount_off = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True) percentage = models.DecimalField(max_digits=3, decimal_places=0, null=True, blank=True) class Meta: constraints = [ AnnotatedCheckConstraint( check=Q(not_null_count=1), annotations={ 'not_null_count': ( NotNullCount( 'amount', 'amount_off', 'percentage', ) ), }, name='%(app_label)s_%(class)s_optional_field_provided', ), ] ``` TODO's ------ - [ ] Add support for schema based functions. - [ ] Add warning about mysql lack of user defined check constraint support. - [ ] Remove skipped sqlite3 test.


نیازمندی

مقدار نام
>=2.2.10 Django
==1.0.0 bump2version
- readme-renderer[md]
==0.7.0 changes
==0.1.0 git-changelog
==1.3.1 twine
==4.4.1 pip-tools
==0.37 check-manifest
>=2.5.4 psycopg2
>=1.3.13 mysqlclient
>=2.2.10 Django
==2019.11.9 nox
>=0.7 pluggy
==2.0.0 mock
==2.5.2 unittest-xml-reporting
==1.3.11 codacy-coverage
==3.4.1 flake8
==1.10.0 yamllint
==4.2.15 isort
==2.0.1 pre-commit
==3.4.1 flake8
==1.10.0 yamllint
==4.2.15 isort
==2.0.1 pre-commit
==2019.11.9 nox
>=0.7 pluggy
==2.0.0 mock
==2.5.2 unittest-xml-reporting
==1.3.11 codacy-coverage
==2019.11.9 nox
>=0.7 pluggy
==2.0.0 mock
==2.5.2 unittest-xml-reporting
==1.3.11 codacy-coverage


زبان مورد نیاز

مقدار نام
>=3.5 Python


نحوه نصب


نصب پکیج whl django-check-constraint-1.0.9:

    pip install django-check-constraint-1.0.9.whl


نصب پکیج tar.gz django-check-constraint-1.0.9:

    pip install django-check-constraint-1.0.9.tar.gz