예제 #1
0
from simple_history.models import HistoricalRecords
from simple_history.admin import SimpleHistoryAdmin, get_complete_version
from ..models import Book, Person, Poll, State, Employee

try:
    from django.contrib.admin.utils import quote
except ImportError:  # Django < 1.7
    from django.contrib.admin.util import quote

User = get_user_model()
today = datetime(2021, 1, 1, 10, 0)
tomorrow = today + timedelta(days=1)

extra_kwargs = {}
if get_complete_version() < (1, 8):
    extra_kwargs = {'current_app': 'admin'}


def get_history_url(obj, history_index=None, site="admin"):
    app, model = obj._meta.app_label, obj._meta.model_name
    if history_index is not None:
        history = obj.history.order_by('history_id')[history_index]
        return reverse(
            "{site}:{app}_{model}_simple_history".format(site=site,
                                                         app=app,
                                                         model=model),
            args=[quote(obj.pk), quote(history.history_id)],
        )
    else:
        return reverse("{site}:{app}_{model}_history".format(site=site,
from simple_history.models import HistoricalRecords
from simple_history.admin import SimpleHistoryAdmin, get_complete_version
from ..models import Book, Person, Poll, State, Employee, Choice

try:
    from django.contrib.admin.utils import quote
except ImportError:  # Django < 1.7
    from django.contrib.admin.util import quote

User = get_user_model()
today = datetime(2021, 1, 1, 10, 0)
tomorrow = today + timedelta(days=1)

extra_kwargs = {}
if get_complete_version() < (1, 8):
    extra_kwargs = {'current_app': 'admin'}


def get_history_url(obj, history_index=None, site="admin"):
    app, model = obj._meta.app_label, obj._meta.model_name
    if history_index is not None:
        history = obj.history.order_by('history_id')[history_index]
        return reverse(
            "{site}:{app}_{model}_simple_history".format(
                site=site, app=app, model=model),
            args=[quote(obj.pk), quote(history.history_id)],
        )
    else:
        return reverse("{site}:{app}_{model}_history".format(
            site=site, app=app, model=model), args=[quote(obj.pk)])