mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
Extend has_feature() to accept a model or OT/CT
This commit is contained in:
parent
9f2ef2b909
commit
943f98e86d
@ -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.
|
Returns True if the model supports the specified feature.
|
||||||
"""
|
"""
|
||||||
# Resolve a ContentType to its model class
|
# If an ObjectType was passed, we can use it directly
|
||||||
if type(model) is ContentType:
|
if type(model_or_ct) is ObjectType:
|
||||||
model = model.model_class()
|
ot = model_or_ct
|
||||||
ot = ObjectType.objects.get_for_model(model)
|
# 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
|
return feature in ot.features
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user