mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 14:23:36 -06:00
Fixes #20137: Ensure proper model resolution for get_for_model() and get_for_models() (#20138)
Some checks failed
Some checks failed
This commit is contained in:
parent
a59da37ac3
commit
7bbb04d2d3
@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
@ -64,6 +65,9 @@ class ObjectTypeManager(models.Manager):
|
|||||||
Retrieve or create and return the ObjectType for a model.
|
Retrieve or create and return the ObjectType for a model.
|
||||||
"""
|
"""
|
||||||
from netbox.models.features import get_model_features, model_is_public
|
from netbox.models.features import get_model_features, model_is_public
|
||||||
|
|
||||||
|
if not inspect.isclass(model):
|
||||||
|
model = model.__class__
|
||||||
opts = self._get_opts(model, for_concrete_model)
|
opts = self._get_opts(model, for_concrete_model)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -75,7 +79,7 @@ class ObjectTypeManager(models.Manager):
|
|||||||
app_label=opts.app_label,
|
app_label=opts.app_label,
|
||||||
model=opts.model_name,
|
model=opts.model_name,
|
||||||
public=model_is_public(model),
|
public=model_is_public(model),
|
||||||
features=get_model_features(model.__class__),
|
features=get_model_features(model),
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
return ot
|
return ot
|
||||||
@ -93,6 +97,8 @@ class ObjectTypeManager(models.Manager):
|
|||||||
needed_models = defaultdict(set)
|
needed_models = defaultdict(set)
|
||||||
needed_opts = defaultdict(list)
|
needed_opts = defaultdict(list)
|
||||||
for model in models:
|
for model in models:
|
||||||
|
if not inspect.isclass(model):
|
||||||
|
model = model.__class__
|
||||||
opts = self._get_opts(model, for_concrete_models)
|
opts = self._get_opts(model, for_concrete_models)
|
||||||
needed_models[opts.app_label].add(opts.model_name)
|
needed_models[opts.app_label].add(opts.model_name)
|
||||||
needed_opts[(opts.app_label, opts.model_name)].append(model)
|
needed_opts[(opts.app_label, opts.model_name)].append(model)
|
||||||
@ -117,7 +123,7 @@ class ObjectTypeManager(models.Manager):
|
|||||||
app_label=app_label,
|
app_label=app_label,
|
||||||
model=model_name,
|
model=model_name,
|
||||||
public=model_is_public(model),
|
public=model_is_public(model),
|
||||||
features=get_model_features(model.__class__),
|
features=get_model_features(model),
|
||||||
)
|
)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
Loading…
Reference in New Issue
Block a user