Fix graph:type choices under /api/extras/_choices/

This commit is contained in:
Jeremy Stretch 2020-01-10 12:18:56 -05:00
parent 830a51d9f5
commit 69a696a8d6
4 changed files with 12 additions and 5 deletions

View File

@ -20,6 +20,7 @@ from utilities.api import (
ChoiceField, ContentTypeField, get_serializer_for_model, SerializerNotFound, SerializedPKRelatedField,
ValidatedModelSerializer,
)
from utilities.utils import model_names_to_filter_dict
from .nested_serializers import *
@ -29,7 +30,7 @@ from .nested_serializers import *
class GraphSerializer(ValidatedModelSerializer):
type = ContentTypeField(
queryset=ContentType.objects.all()
queryset=ContentType.objects.filter(**model_names_to_filter_dict(GRAPH_MODELS)),
)
class Meta:

View File

@ -42,6 +42,14 @@ CUSTOMLINK_MODELS = [
'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
EXPORTTEMPLATE_MODELS = [
'circuits.circuit',

View File

@ -38,7 +38,7 @@ class Migration(migrations.Migration):
model_name='graph',
name='type',
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,
to='contenttypes.ContentType'
),

View File

@ -410,9 +410,7 @@ class Graph(models.Model):
type = models.ForeignKey(
to=ContentType,
on_delete=models.CASCADE,
limit_choices_to={
'model__in': ['device', 'interface', 'provider', 'site']
}
limit_choices_to=model_names_to_filter_dict(GRAPH_MODELS)
)
weight = models.PositiveSmallIntegerField(
default=1000