File: __init__.py

package info (click to toggle)
python-django-simple-history 3.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,124 kB
  • sloc: python: 8,454; makefile: 186
file content (39 lines) | stat: -rw-r--r-- 1,197 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from importlib import metadata

__version__ = metadata.version("django-simple-history")


def register(
    model,
    app=None,
    manager_name="history",
    records_class=None,
    table_name=None,
    **records_config,
):
    """
    Create historical model for `model` and attach history manager to `model`.

    Keyword arguments:
    app -- App to install historical model into (defaults to model.__module__)
    manager_name -- class attribute name to use for historical manager
    records_class -- class to use for history relation (defaults to
        HistoricalRecords)
    table_name -- Custom name for history table (defaults to
        'APPNAME_historicalMODELNAME')

    This method should be used as an alternative to attaching an
    `HistoricalManager` instance directly to `model`.
    """
    from . import models

    if records_class is None:
        records_class = models.HistoricalRecords

    records = records_class(**records_config)
    records.manager_name = manager_name
    records.table_name = table_name
    records.module = app and ("%s.models" % app) or model.__module__
    records.cls = model
    records.add_extra_methods(model)
    records.finalize(model)