Skip to content

Commit 8549a3f

Browse files
Add get_crm_url method to BaseContact model
This new method returns the URL for a given object on the CRM site using Django's reverse function. This makes it easier to programmatically access the CRM page for any contact instance.
1 parent b18584e commit 8549a3f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crm/models/base_contact.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.contenttypes.models import ContentType
22
from django.db import models
3+
from django.urls import reverse
34
from django.utils.translation import gettext_lazy as _
45

56
from common.utils.helpers import get_today
@@ -164,3 +165,7 @@ def delete(self, *args, **kwargs):
164165
except MassContact.DoesNotExist:
165166
pass
166167
super().delete(*args, **kwargs)
168+
169+
def get_crm_url(self) -> str:
170+
"""Returns the URL of an object on the CRM site"""
171+
return reverse(f'site:crm_{self._meta.model_name}_change', args=(self.id,))

0 commit comments

Comments
 (0)