Skip to content

Commit

Permalink
Merge branch 'release/0.3.38' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 24, 2024
2 parents 29ace12 + a824dd4 commit cbf0fdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions edc_model/models/url_model_mixin.py
Expand Up @@ -21,9 +21,8 @@ def get_absolute_url(self) -> str:
except NoReverseMatch as e:
raise UrlModelMixinNoReverseMatch(
f"Tried {self.admin_url_name}. Got {e}. "
"Confirm app is in INSTALLED_APPS. If running tests, you may need to set "
"`use_test_urls=True`. Otherwise, define AppConfig.admin_site_name or directly"
"on model.ADMIN_SITE_NAME that refers to your app specific admin site. "
"Check urls and confirm app is in INSTALLED_APPS. If running tests, "
"you may need to set `use_test_urls=True`."
)
return absolute_url

Expand Down
7 changes: 7 additions & 0 deletions edc_model/utils.py
Expand Up @@ -9,6 +9,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db.models import CharField, DateField, DateTimeField, Model
from django.urls import reverse

from .constants import REPORT_DATETIME_FIELD_NAME

Expand Down Expand Up @@ -206,3 +207,9 @@ def duration_dh_to_timedelta(duration_text: str | CharField) -> timedelta:
hours_str = duration_text.split("h")[0]
hours = int(hours_str)
return timedelta(days=days, hours=hours)


def get_history_url(obj, admin_site: str = None) -> str:
admin_site = admin_site or obj.admin_url_name.split(":")[0]
app, model = obj._meta.app_label, obj._meta.model_name
return reverse(f"{admin_site}:{app}_{model}_history", args=[str(obj.pk)])

0 comments on commit cbf0fdf

Please sign in to comment.