diff --git a/employee/methods/methods.py b/employee/methods/methods.py index 48162dab2..1ffa2deba 100644 --- a/employee/methods/methods.py +++ b/employee/methods/methods.py @@ -5,6 +5,8 @@ employee/methods.py import re from itertools import groupby +from django.db import models + from base.context_processors import get_initial_prefix from employee.models import Employee @@ -60,3 +62,17 @@ def get_ordered_badge_ids(): if pure_numbers: result.insert(0, [pure_numbers[0], pure_numbers[-1]]) return result + + +def check_relationship_with_employee_model(model): + related_fields = [] + for field in model._meta.get_fields(): + # Check if the field is a ForeignKey or ManyToManyField and related to Employee + if isinstance(field, models.ForeignKey) and field.related_model == Employee: + related_fields.append((field.name, "ForeignKey")) + elif ( + isinstance(field, models.ManyToManyField) + and field.related_model == Employee + ): + related_fields.append((field.name, "ManyToManyField")) + return related_fields diff --git a/horilla_automations/methods/methods.py b/horilla_automations/methods/methods.py index 9ceb53422..3a3e3709a 100644 --- a/horilla_automations/methods/methods.py +++ b/horilla_automations/methods/methods.py @@ -90,7 +90,6 @@ def get_model_class(model_path): method to return the model class from string 'app.models.Model' """ module_name, class_name = model_path.rsplit(".", 1) - module = __import__(module_name, fromlist=[class_name]) model_class: Employee = getattr(module, class_name) return model_class