File: __init__.py

package info (click to toggle)
mssql-django 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 644 kB
  • sloc: python: 5,289; sh: 105; makefile: 7
file content (17 lines) | stat: -rw-r--r-- 461 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import django.db


def get_constraints(table_name):
    connection = django.db.connections[django.db.DEFAULT_DB_ALIAS]
    return connection.introspection.get_constraints(
        connection.cursor(),
        table_name=table_name,
    )


def get_constraint_names_where(table_name, **kwargs):
    return [
        name
        for name, details in get_constraints(table_name=table_name).items()
        if all(details[k] == v for k, v in kwargs.items())
    ]