File: util.py

package info (click to toggle)
python-django-postgres-extra 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: python: 9,057; makefile: 17; sh: 7; sql: 1
file content (24 lines) | stat: -rw-r--r-- 530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from contextlib import contextmanager
from typing import Generator, Type

from django.db import models

from .manager import PostgresManager


@contextmanager
def postgres_manager(
    model: Type[models.Model],
) -> Generator[PostgresManager, None, None]:
    """Allows you to use the :see:PostgresManager with the specified model
    instance on the fly.

    Arguments:
        model:
            The model or model instance to use this on.
    """

    manager = PostgresManager()
    manager.model = model

    yield manager