mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce is_taggable utility function for identifying taggable models
This commit is contained in:
15
netbox/extras/utils.py
Normal file
15
netbox/extras/utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
from taggit.managers import _TaggableManager
|
||||
from utilities.querysets import DummyQuerySet
|
||||
|
||||
|
||||
def is_taggable(obj):
|
||||
"""
|
||||
Return True if the instance can have Tags assigned to it; False otherwise.
|
||||
"""
|
||||
if hasattr(obj, 'tags'):
|
||||
if issubclass(obj.tags.__class__, _TaggableManager):
|
||||
return True
|
||||
# TaggableManager has been replaced with a DummyQuerySet prior to object deletion
|
||||
if isinstance(obj.tags, DummyQuerySet):
|
||||
return True
|
||||
return False
|
Reference in New Issue
Block a user