From 943f98e86d521eff2193c1fa96e559a5e052315c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 24 Jul 2025 09:29:27 -0400 Subject: [PATCH] Extend has_feature() to accept a model or OT/CT --- netbox/netbox/models/features.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index 39ae76dea..7f471a878 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -654,14 +654,19 @@ def get_model_features(model): ] -def has_feature(model, feature): +def has_feature(model_or_ct, feature): """ Returns True if the model supports the specified feature. """ - # Resolve a ContentType to its model class - if type(model) is ContentType: - model = model.model_class() - ot = ObjectType.objects.get_for_model(model) + # If an ObjectType was passed, we can use it directly + if type(model_or_ct) is ObjectType: + ot = model_or_ct + # If a ContentType was passed, resolve its model class + elif type(model_or_ct) is ContentType: + ot = ObjectType.objects.get_for_model(model_or_ct.model_class()) + # For anything else, look up the ObjectType + else: + ot = ObjectType.objects.get_for_model(model_or_ct) return feature in ot.features