Skip to content

Commit

Permalink
Allow passing functions instead of module
Browse files Browse the repository at this point in the history
  • Loading branch information
ktg-123 committed Dec 24, 2021
1 parent 794846e commit ff6e040
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions fcm_django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,11 @@ def save(self, *args, **kwargs):
self.process_db_object_saved()

def process_db_object_saved(self):
if SETTINGS["THIRD_PARTY_SERVICE"]:
_class = getattr(importlib.import_module(SETTINGS["THIRD_PARTY_SERVICE"]), "FCMDeviceTrigger")
_class.db_object_trigger(
if SETTINGS["POST_FCM_SAVE_FUNCTION"]:
module_name, function_name = SETTINGS["POST_FCM_SAVE_FUNCTION"].rsplit(".", 1)
module = importlib.import_module(module_name)
function = getattr(module, function_name)
function(
self.original_object, self
)

Expand Down
4 changes: 2 additions & 2 deletions fcm_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# User model
FCM_DJANGO_SETTINGS.setdefault("USER_MODEL", settings.AUTH_USER_MODEL)

# THIRD PARTY SERVICE
FCM_DJANGO_SETTINGS.setdefault("THIRD_PARTY_SERVICE", "")
# Post FCM Save Function
FCM_DJANGO_SETTINGS.setdefault("POST_FCM_SAVE_FUNCTION", "")

FCM_DJANGO_SETTINGS.setdefault(
"ERRORS",
Expand Down

0 comments on commit ff6e040

Please sign in to comment.