Skip to content

Commit 943f98e

Browse files
committed
Extend has_feature() to accept a model or OT/CT
1 parent 9f2ef2b commit 943f98e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

netbox/netbox/models/features.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,19 @@ def get_model_features(model):
654654
]
655655

656656

657-
def has_feature(model, feature):
657+
def has_feature(model_or_ct, feature):
658658
"""
659659
Returns True if the model supports the specified feature.
660660
"""
661-
# Resolve a ContentType to its model class
662-
if type(model) is ContentType:
663-
model = model.model_class()
664-
ot = ObjectType.objects.get_for_model(model)
661+
# If an ObjectType was passed, we can use it directly
662+
if type(model_or_ct) is ObjectType:
663+
ot = model_or_ct
664+
# If a ContentType was passed, resolve its model class
665+
elif type(model_or_ct) is ContentType:
666+
ot = ObjectType.objects.get_for_model(model_or_ct.model_class())
667+
# For anything else, look up the ObjectType
668+
else:
669+
ot = ObjectType.objects.get_for_model(model_or_ct)
665670
return feature in ot.features
666671

667672

0 commit comments

Comments
 (0)