1
0
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:
Jeremy Stretch
2019-12-11 15:26:47 -05:00
parent 8b189abd58
commit ce4a5a38a3
4 changed files with 22 additions and 4 deletions

15
netbox/extras/utils.py Normal file
View 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