mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#3892: Convert GRAPH_MODELS to a Q object
This commit is contained in:
@ -30,7 +30,7 @@ from .nested_serializers import *
|
|||||||
|
|
||||||
class GraphSerializer(ValidatedModelSerializer):
|
class GraphSerializer(ValidatedModelSerializer):
|
||||||
type = ContentTypeField(
|
type = ContentTypeField(
|
||||||
queryset=ContentType.objects.filter(**model_names_to_filter_dict(GRAPH_MODELS)),
|
queryset=ContentType.objects.filter(GRAPH_MODELS),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -70,11 +70,15 @@ CUSTOMLINK_MODELS = Q(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Models which can have Graphs associated with them
|
# Models which can have Graphs associated with them
|
||||||
GRAPH_MODELS = (
|
GRAPH_MODELS = Q(
|
||||||
'circuits.provider',
|
Q(app_label='circuits', model__in=[
|
||||||
'dcim.device',
|
'provider',
|
||||||
'dcim.interface',
|
]) |
|
||||||
'dcim.site',
|
Q(app_label='dcim', model__in=[
|
||||||
|
'device',
|
||||||
|
'interface',
|
||||||
|
'site',
|
||||||
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
# Models which support export templates
|
# Models which support export templates
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Generated by Django 2.2.8 on 2020-01-15 21:04
|
# Generated by Django 2.2.8 on 2020-01-15 21:07
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
@ -21,4 +21,9 @@ class Migration(migrations.Migration):
|
|||||||
name='content_type',
|
name='content_type',
|
||||||
field=models.ForeignKey(limit_choices_to=models.Q(models.Q(models.Q(('app_label', 'circuits'), ('model__in', ['circuit', 'provider'])), models.Q(('app_label', 'dcim'), ('model__in', ['cable', 'device', 'devicetype', 'powerpanel', 'powerfeed', 'rack', 'site'])), models.Q(('app_label', 'ipam'), ('model__in', ['aggregate', 'ipaddress', 'prefix', 'service', 'vlan', 'vrf'])), models.Q(('app_label', 'secrets'), ('model__in', ['secret'])), models.Q(('app_label', 'tenancy'), ('model__in', ['tenant'])), models.Q(('app_label', 'virtualization'), ('model__in', ['cluster', 'virtualmachine'])), _connector='OR')), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
field=models.ForeignKey(limit_choices_to=models.Q(models.Q(models.Q(('app_label', 'circuits'), ('model__in', ['circuit', 'provider'])), models.Q(('app_label', 'dcim'), ('model__in', ['cable', 'device', 'devicetype', 'powerpanel', 'powerfeed', 'rack', 'site'])), models.Q(('app_label', 'ipam'), ('model__in', ['aggregate', 'ipaddress', 'prefix', 'service', 'vlan', 'vrf'])), models.Q(('app_label', 'secrets'), ('model__in', ['secret'])), models.Q(('app_label', 'tenancy'), ('model__in', ['tenant'])), models.Q(('app_label', 'virtualization'), ('model__in', ['cluster', 'virtualmachine'])), _connector='OR')), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
||||||
),
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='graph',
|
||||||
|
name='type',
|
||||||
|
field=models.ForeignKey(limit_choices_to=models.Q(models.Q(models.Q(('app_label', 'circuits'), ('model__in', ['provider'])), models.Q(('app_label', 'dcim'), ('model__in', ['device', 'interface', 'site'])), _connector='OR')), on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -423,7 +423,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=model_names_to_filter_dict(GRAPH_MODELS)
|
limit_choices_to=GRAPH_MODELS
|
||||||
)
|
)
|
||||||
weight = models.PositiveSmallIntegerField(
|
weight = models.PositiveSmallIntegerField(
|
||||||
default=1000
|
default=1000
|
||||||
|
@ -29,7 +29,7 @@ class ChoicesTest(APITestCase):
|
|||||||
self.assertEqual(choices_to_dict(response.data.get('export-template:template_language')), TemplateLanguageChoices.as_dict())
|
self.assertEqual(choices_to_dict(response.data.get('export-template:template_language')), TemplateLanguageChoices.as_dict())
|
||||||
|
|
||||||
# Graph
|
# Graph
|
||||||
content_types = ContentType.objects.filter(**model_names_to_filter_dict(GRAPH_MODELS))
|
content_types = ContentType.objects.filter(GRAPH_MODELS)
|
||||||
graph_type_choices = {
|
graph_type_choices = {
|
||||||
"{}.{}".format(ct.app_label, ct.model): ct.name for ct in content_types
|
"{}.{}".format(ct.app_label, ct.model): ct.name for ct in content_types
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user