1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #7858: Standardize the representation of content types across import & export functions

This commit is contained in:
jeremystretch
2021-11-17 11:02:22 -05:00
parent 6f7fbf7686
commit 9de179cba8
5 changed files with 35 additions and 11 deletions

View File

@ -344,16 +344,23 @@ def array_to_string(array):
return ', '.join('-'.join(map(str, (g[0], g[-1])[:len(g)])) for g in group)
def content_type_name(contenttype):
def content_type_name(ct):
"""
Return a proper ContentType name.
Return a human-friendly ContentType name (e.g. "DCIM > Site").
"""
try:
meta = contenttype.model_class()._meta
meta = ct.model_class()._meta
return f'{meta.app_config.verbose_name} > {meta.verbose_name}'
except AttributeError:
# Model no longer exists
return f'{contenttype.app_label} > {contenttype.model}'
return f'{ct.app_label} > {ct.model}'
def content_type_identifier(ct):
"""
Return a "raw" ContentType identifier string suitable for bulk import/export (e.g. "dcim.site").
"""
return f'{ct.app_label}.{ct.model}'
#