mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Fix graph:type choices under /api/extras/_choices/
This commit is contained in:
parent
830a51d9f5
commit
69a696a8d6
@ -20,6 +20,7 @@ from utilities.api import (
|
|||||||
ChoiceField, ContentTypeField, get_serializer_for_model, SerializerNotFound, SerializedPKRelatedField,
|
ChoiceField, ContentTypeField, get_serializer_for_model, SerializerNotFound, SerializedPKRelatedField,
|
||||||
ValidatedModelSerializer,
|
ValidatedModelSerializer,
|
||||||
)
|
)
|
||||||
|
from utilities.utils import model_names_to_filter_dict
|
||||||
from .nested_serializers import *
|
from .nested_serializers import *
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ from .nested_serializers import *
|
|||||||
|
|
||||||
class GraphSerializer(ValidatedModelSerializer):
|
class GraphSerializer(ValidatedModelSerializer):
|
||||||
type = ContentTypeField(
|
type = ContentTypeField(
|
||||||
queryset=ContentType.objects.all()
|
queryset=ContentType.objects.filter(**model_names_to_filter_dict(GRAPH_MODELS)),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -42,6 +42,14 @@ CUSTOMLINK_MODELS = [
|
|||||||
'virtualization.virtualmachine',
|
'virtualization.virtualmachine',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Models which can have Graphs associated with them
|
||||||
|
GRAPH_MODELS = (
|
||||||
|
'circuits.provider',
|
||||||
|
'dcim.device',
|
||||||
|
'dcim.interface',
|
||||||
|
'dcim.site',
|
||||||
|
)
|
||||||
|
|
||||||
# Models which support export templates
|
# Models which support export templates
|
||||||
EXPORTTEMPLATE_MODELS = [
|
EXPORTTEMPLATE_MODELS = [
|
||||||
'circuits.circuit',
|
'circuits.circuit',
|
||||||
|
@ -38,7 +38,7 @@ class Migration(migrations.Migration):
|
|||||||
model_name='graph',
|
model_name='graph',
|
||||||
name='type',
|
name='type',
|
||||||
field=models.ForeignKey(
|
field=models.ForeignKey(
|
||||||
limit_choices_to={'model__in': ['device', 'interface', 'provider', 'site']},
|
limit_choices_to={'model__in': ['provider', 'device', 'interface', 'site']},
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
to='contenttypes.ContentType'
|
to='contenttypes.ContentType'
|
||||||
),
|
),
|
||||||
|
@ -410,9 +410,7 @@ class Graph(models.Model):
|
|||||||
type = models.ForeignKey(
|
type = models.ForeignKey(
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
limit_choices_to={
|
limit_choices_to=model_names_to_filter_dict(GRAPH_MODELS)
|
||||||
'model__in': ['device', 'interface', 'provider', 'site']
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
weight = models.PositiveSmallIntegerField(
|
weight = models.PositiveSmallIntegerField(
|
||||||
default=1000
|
default=1000
|
||||||
|
Loading…
Reference in New Issue
Block a user