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

Closes #14153: Filter ContentTypes by supported feature (#14191)

* WIP

* Remove FeatureQuery

* Standardize use of proxy ContentType for models

* Remove TODO

* Correctly filter BookmarksWidget object_types choices

* Add feature-specific object type validation
This commit is contained in:
Jeremy Stretch
2023-11-16 12:12:51 -05:00
committed by GitHub
parent 69a4c31072
commit e15647a2ce
30 changed files with 152 additions and 142 deletions

View File

@@ -1,13 +1,12 @@
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from netbox.models import ChangeLoggedModel, PrimaryModel
from ipam.choices import *
from ipam.constants import *
from netbox.models import ChangeLoggedModel, PrimaryModel
__all__ = (
'FHRPGroup',
@@ -78,7 +77,7 @@ class FHRPGroup(PrimaryModel):
class FHRPGroupAssignment(ChangeLoggedModel):
interface_type = models.ForeignKey(
to=ContentType,
to='contenttypes.ContentType',
on_delete=models.CASCADE
)
interface_id = models.PositiveBigIntegerField()

View File

@@ -1,6 +1,5 @@
import netaddr
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import F
@@ -9,6 +8,7 @@ from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from core.models import ContentType
from ipam.choices import *
from ipam.constants import *
from ipam.fields import IPNetworkField, IPAddressField
@@ -740,7 +740,7 @@ class IPAddress(PrimaryModel):
help_text=_('The functional role of this IP')
)
assigned_object_type = models.ForeignKey(
to=ContentType,
to='contenttypes.ContentType',
limit_choices_to=IPADDRESS_ASSIGNMENT_MODELS,
on_delete=models.PROTECT,
related_name='+',

View File

@@ -1,11 +1,11 @@
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from core.models import ContentType
from ipam.choices import L2VPNTypeChoices
from ipam.constants import L2VPN_ASSIGNMENT_MODELS
from netbox.models import NetBoxModel, PrimaryModel
@@ -86,7 +86,7 @@ class L2VPNTermination(NetBoxModel):
related_name='terminations'
)
assigned_object_type = models.ForeignKey(
to=ContentType,
to='contenttypes.ContentType',
limit_choices_to=L2VPN_ASSIGNMENT_MODELS,
on_delete=models.PROTECT,
related_name='+'

View File

@@ -1,5 +1,4 @@
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
@@ -32,7 +31,7 @@ class VLANGroup(OrganizationalModel):
max_length=100
)
scope_type = models.ForeignKey(
to=ContentType,
to='contenttypes.ContentType',
on_delete=models.CASCADE,
limit_choices_to=Q(model__in=VLANGROUP_SCOPE_TYPES),
blank=True,