mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Rename ContentType proxy model to ObjectType
This commit is contained in:
@@ -7,7 +7,7 @@ from rest_framework import serializers
|
||||
|
||||
from core.api.nested_serializers import NestedDataSourceSerializer, NestedDataFileSerializer, NestedJobSerializer
|
||||
from core.api.serializers import JobSerializer
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from dcim.api.nested_serializers import (
|
||||
NestedDeviceRoleSerializer, NestedDeviceTypeSerializer, NestedLocationSerializer, NestedPlatformSerializer,
|
||||
NestedRegionSerializer, NestedSiteSerializer, NestedSiteGroupSerializer,
|
||||
@@ -60,12 +60,12 @@ __all__ = (
|
||||
class EventRuleSerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:eventrule-detail')
|
||||
content_types = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('event_rules'),
|
||||
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||
many=True
|
||||
)
|
||||
action_type = ChoiceField(choices=EventRuleActionChoices)
|
||||
action_object_type = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('event_rules'),
|
||||
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||
)
|
||||
action_object = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
@@ -118,12 +118,12 @@ class WebhookSerializer(NetBoxModelSerializer):
|
||||
class CustomFieldSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customfield-detail')
|
||||
content_types = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
||||
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||
many=True
|
||||
)
|
||||
type = ChoiceField(choices=CustomFieldTypeChoices)
|
||||
object_type = ContentTypeField(
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
required=False,
|
||||
allow_null=True
|
||||
)
|
||||
@@ -197,7 +197,7 @@ class CustomFieldChoiceSetSerializer(ValidatedModelSerializer):
|
||||
class CustomLinkSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customlink-detail')
|
||||
content_types = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('custom_links'),
|
||||
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||
many=True
|
||||
)
|
||||
|
||||
@@ -217,7 +217,7 @@ class CustomLinkSerializer(ValidatedModelSerializer):
|
||||
class ExportTemplateSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:exporttemplate-detail')
|
||||
content_types = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('export_templates'),
|
||||
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||
many=True
|
||||
)
|
||||
data_source = NestedDataSourceSerializer(
|
||||
@@ -244,7 +244,7 @@ class ExportTemplateSerializer(ValidatedModelSerializer):
|
||||
class SavedFilterSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:savedfilter-detail')
|
||||
content_types = ContentTypeField(
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
many=True
|
||||
)
|
||||
|
||||
@@ -264,7 +264,7 @@ class SavedFilterSerializer(ValidatedModelSerializer):
|
||||
class BookmarkSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:bookmark-detail')
|
||||
object_type = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('bookmarks'),
|
||||
queryset=ObjectType.objects.with_feature('bookmarks'),
|
||||
)
|
||||
object = serializers.SerializerMethodField(read_only=True)
|
||||
user = NestedUserSerializer()
|
||||
@@ -289,7 +289,7 @@ class BookmarkSerializer(ValidatedModelSerializer):
|
||||
class TagSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:tag-detail')
|
||||
object_types = ContentTypeField(
|
||||
queryset=ContentType.objects.with_feature('tags'),
|
||||
queryset=ObjectType.objects.with_feature('tags'),
|
||||
many=True,
|
||||
required=False
|
||||
)
|
||||
@@ -313,7 +313,7 @@ class TagSerializer(ValidatedModelSerializer):
|
||||
class ImageAttachmentSerializer(ValidatedModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:imageattachment-detail')
|
||||
content_type = ContentTypeField(
|
||||
queryset=ContentType.objects.all()
|
||||
queryset=ObjectType.objects.all()
|
||||
)
|
||||
parent = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
@@ -353,7 +353,7 @@ class ImageAttachmentSerializer(ValidatedModelSerializer):
|
||||
class JournalEntrySerializer(NetBoxModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:journalentry-detail')
|
||||
assigned_object_type = ContentTypeField(
|
||||
queryset=ContentType.objects.all()
|
||||
queryset=ObjectType.objects.all()
|
||||
)
|
||||
assigned_object = serializers.SerializerMethodField(read_only=True)
|
||||
created_by = serializers.PrimaryKeyRelatedField(
|
||||
@@ -645,7 +645,7 @@ class ContentTypeSerializer(BaseModelSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:contenttype-detail')
|
||||
|
||||
class Meta:
|
||||
model = ContentType
|
||||
model = ObjectType
|
||||
fields = ['id', 'url', 'display', 'app_label', 'model']
|
||||
|
||||
|
||||
|
@@ -12,7 +12,7 @@ from django.template.loader import render_to_string
|
||||
from django.urls import NoReverseMatch, resolve, reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from extras.choices import BookmarkOrderingChoices
|
||||
from utilities.choices import ButtonColorChoices
|
||||
from utilities.permissions import get_permission_for_model
|
||||
@@ -34,14 +34,14 @@ __all__ = (
|
||||
def get_object_type_choices():
|
||||
return [
|
||||
(content_type_identifier(ct), content_type_name(ct))
|
||||
for ct in ContentType.objects.public().order_by('app_label', 'model')
|
||||
for ct in ObjectType.objects.public().order_by('app_label', 'model')
|
||||
]
|
||||
|
||||
|
||||
def get_bookmarks_object_type_choices():
|
||||
return [
|
||||
(content_type_identifier(ct), content_type_name(ct))
|
||||
for ct in ContentType.objects.with_feature('bookmarks').order_by('app_label', 'model')
|
||||
for ct in ObjectType.objects.with_feature('bookmarks').order_by('app_label', 'model')
|
||||
]
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ def get_models_from_content_types(content_types):
|
||||
models = []
|
||||
for content_type_id in content_types:
|
||||
app_label, model_name = content_type_id.split('.')
|
||||
content_type = ContentType.objects.get_by_natural_key(app_label, model_name)
|
||||
content_type = ObjectType.objects.get_by_natural_key(app_label, model_name)
|
||||
models.append(content_type.model_class())
|
||||
return models
|
||||
|
||||
@@ -238,7 +238,7 @@ class ObjectListWidget(DashboardWidget):
|
||||
|
||||
def render(self, request):
|
||||
app_label, model_name = self.config['model'].split('.')
|
||||
model = ContentType.objects.get_by_natural_key(app_label, model_name).model_class()
|
||||
model = ObjectType.objects.get_by_natural_key(app_label, model_name).model_class()
|
||||
viewname = get_viewname(model, action='list')
|
||||
|
||||
# Evaluate user's permission. Note that this controls only whether the HTMX element is
|
||||
@@ -371,7 +371,7 @@ class BookmarksWidget(DashboardWidget):
|
||||
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by'])
|
||||
if object_types := self.config.get('object_types'):
|
||||
models = get_models_from_content_types(object_types)
|
||||
conent_types = ContentType.objects.get_for_models(*models).values()
|
||||
conent_types = ObjectType.objects.get_for_models(*models).values()
|
||||
bookmarks = bookmarks.filter(object_type__in=conent_types)
|
||||
if max_items := self.config.get('max_items'):
|
||||
bookmarks = bookmarks[:max_items]
|
||||
|
@@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from extras.choices import *
|
||||
from extras.models import *
|
||||
from netbox.forms import NetBoxModelImportForm
|
||||
@@ -32,7 +32,7 @@ __all__ = (
|
||||
class CustomFieldImportForm(CSVModelForm):
|
||||
content_types = CSVMultipleContentTypeField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
||||
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||
help_text=_("One or more assigned object types")
|
||||
)
|
||||
type = CSVChoiceField(
|
||||
@@ -42,7 +42,7 @@ class CustomFieldImportForm(CSVModelForm):
|
||||
)
|
||||
object_type = CSVContentTypeField(
|
||||
label=_('Object type'),
|
||||
queryset=ContentType.objects.public(),
|
||||
queryset=ObjectType.objects.public(),
|
||||
required=False,
|
||||
help_text=_("Object type (for object or multi-object fields)")
|
||||
)
|
||||
@@ -113,7 +113,7 @@ class CustomFieldChoiceSetImportForm(CSVModelForm):
|
||||
class CustomLinkImportForm(CSVModelForm):
|
||||
content_types = CSVMultipleContentTypeField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('custom_links'),
|
||||
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||
help_text=_("One or more assigned object types")
|
||||
)
|
||||
|
||||
@@ -128,7 +128,7 @@ class CustomLinkImportForm(CSVModelForm):
|
||||
class ExportTemplateImportForm(CSVModelForm):
|
||||
content_types = CSVMultipleContentTypeField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('export_templates'),
|
||||
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||
help_text=_("One or more assigned object types")
|
||||
)
|
||||
|
||||
@@ -151,7 +151,7 @@ class ConfigTemplateImportForm(CSVModelForm):
|
||||
class SavedFilterImportForm(CSVModelForm):
|
||||
content_types = CSVMultipleContentTypeField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
help_text=_("One or more assigned object types")
|
||||
)
|
||||
|
||||
@@ -175,7 +175,7 @@ class WebhookImportForm(NetBoxModelImportForm):
|
||||
class EventRuleImportForm(NetBoxModelImportForm):
|
||||
content_types = CSVMultipleContentTypeField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('event_rules'),
|
||||
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||
help_text=_("One or more assigned object types")
|
||||
)
|
||||
action_object = forms.CharField(
|
||||
@@ -213,7 +213,7 @@ class EventRuleImportForm(NetBoxModelImportForm):
|
||||
except ObjectDoesNotExist:
|
||||
raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
|
||||
self.instance.action_object = script
|
||||
self.instance.action_object_type = ContentType.objects.get_for_model(script, for_concrete_model=False)
|
||||
self.instance.action_object_type = ObjectType.objects.get_for_model(script, for_concrete_model=False)
|
||||
|
||||
|
||||
class TagImportForm(CSVModelForm):
|
||||
@@ -229,7 +229,7 @@ class TagImportForm(CSVModelForm):
|
||||
|
||||
class JournalEntryImportForm(NetBoxModelImportForm):
|
||||
assigned_object_type = CSVContentTypeField(
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
label=_('Assigned object type'),
|
||||
)
|
||||
kind = CSVChoiceField(
|
||||
|
@@ -2,7 +2,7 @@ from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import ContentType, DataFile, DataSource
|
||||
from core.models import ObjectType, DataFile, DataSource
|
||||
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
||||
from extras.choices import *
|
||||
from extras.models import *
|
||||
@@ -43,7 +43,7 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
|
||||
)),
|
||||
)
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
||||
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||
required=False,
|
||||
label=_('Object type')
|
||||
)
|
||||
@@ -112,7 +112,7 @@ class CustomLinkFilterForm(SavedFiltersMixin, FilterForm):
|
||||
)
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('custom_links'),
|
||||
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||
required=False
|
||||
)
|
||||
enabled = forms.NullBooleanField(
|
||||
@@ -155,7 +155,7 @@ class ExportTemplateFilterForm(SavedFiltersMixin, FilterForm):
|
||||
}
|
||||
)
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
queryset=ContentType.objects.with_feature('export_templates'),
|
||||
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||
required=False,
|
||||
label=_('Content types')
|
||||
)
|
||||
@@ -183,7 +183,7 @@ class ImageAttachmentFilterForm(SavedFiltersMixin, FilterForm):
|
||||
)
|
||||
content_type_id = ContentTypeChoiceField(
|
||||
label=_('Content type'),
|
||||
queryset=ContentType.objects.with_feature('image_attachments'),
|
||||
queryset=ObjectType.objects.with_feature('image_attachments'),
|
||||
required=False
|
||||
)
|
||||
name = forms.CharField(
|
||||
@@ -199,7 +199,7 @@ class SavedFilterFilterForm(SavedFiltersMixin, FilterForm):
|
||||
)
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.public(),
|
||||
queryset=ObjectType.objects.public(),
|
||||
required=False
|
||||
)
|
||||
enabled = forms.NullBooleanField(
|
||||
@@ -254,7 +254,7 @@ class EventRuleFilterForm(NetBoxModelFilterSetForm):
|
||||
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
|
||||
)
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
queryset=ContentType.objects.with_feature('event_rules'),
|
||||
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||
required=False,
|
||||
label=_('Object type')
|
||||
)
|
||||
@@ -310,12 +310,12 @@ class EventRuleFilterForm(NetBoxModelFilterSetForm):
|
||||
class TagFilterForm(SavedFiltersMixin, FilterForm):
|
||||
model = Tag
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
queryset=ContentType.objects.with_feature('tags'),
|
||||
queryset=ObjectType.objects.with_feature('tags'),
|
||||
required=False,
|
||||
label=_('Tagged object type')
|
||||
)
|
||||
for_object_type_id = ContentTypeChoiceField(
|
||||
queryset=ContentType.objects.with_feature('tags'),
|
||||
queryset=ObjectType.objects.with_feature('tags'),
|
||||
required=False,
|
||||
label=_('Allowed object type')
|
||||
)
|
||||
@@ -464,7 +464,7 @@ class JournalEntryFilterForm(NetBoxModelFilterSetForm):
|
||||
label=_('User')
|
||||
)
|
||||
assigned_object_type_id = DynamicModelMultipleChoiceField(
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
required=False,
|
||||
label=_('Object Type'),
|
||||
widget=APISelectMultiple(
|
||||
@@ -507,7 +507,7 @@ class ObjectChangeFilterForm(SavedFiltersMixin, FilterForm):
|
||||
label=_('User')
|
||||
)
|
||||
changed_object_type_id = DynamicModelMultipleChoiceField(
|
||||
queryset=ContentType.objects.all(),
|
||||
queryset=ObjectType.objects.all(),
|
||||
required=False,
|
||||
label=_('Object Type'),
|
||||
widget=APISelectMultiple(
|
||||
|
@@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.forms.mixins import SyncedDataMixin
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
||||
from extras.choices import *
|
||||
from extras.models import *
|
||||
@@ -41,11 +41,11 @@ __all__ = (
|
||||
class CustomFieldForm(forms.ModelForm):
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('custom_fields')
|
||||
queryset=ObjectType.objects.with_feature('custom_fields')
|
||||
)
|
||||
object_type = ContentTypeChoiceField(
|
||||
label=_('Object type'),
|
||||
queryset=ContentType.objects.public(),
|
||||
queryset=ObjectType.objects.public(),
|
||||
required=False,
|
||||
help_text=_("Type of the related object (for object/multi-object fields only)")
|
||||
)
|
||||
@@ -125,7 +125,7 @@ class CustomFieldChoiceSetForm(forms.ModelForm):
|
||||
class CustomLinkForm(forms.ModelForm):
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('custom_links')
|
||||
queryset=ObjectType.objects.with_feature('custom_links')
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
@@ -154,7 +154,7 @@ class CustomLinkForm(forms.ModelForm):
|
||||
class ExportTemplateForm(SyncedDataMixin, forms.ModelForm):
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('export_templates')
|
||||
queryset=ObjectType.objects.with_feature('export_templates')
|
||||
)
|
||||
template_code = forms.CharField(
|
||||
label=_('Template code'),
|
||||
@@ -195,7 +195,7 @@ class SavedFilterForm(forms.ModelForm):
|
||||
slug = SlugField()
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.all()
|
||||
queryset=ObjectType.objects.all()
|
||||
)
|
||||
parameters = JSONField()
|
||||
|
||||
@@ -221,7 +221,7 @@ class SavedFilterForm(forms.ModelForm):
|
||||
class BookmarkForm(forms.ModelForm):
|
||||
object_type = ContentTypeChoiceField(
|
||||
label=_('Object type'),
|
||||
queryset=ContentType.objects.with_feature('bookmarks')
|
||||
queryset=ObjectType.objects.with_feature('bookmarks')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -251,7 +251,7 @@ class WebhookForm(NetBoxModelForm):
|
||||
class EventRuleForm(NetBoxModelForm):
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Content types'),
|
||||
queryset=ContentType.objects.with_feature('event_rules'),
|
||||
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||
)
|
||||
action_choice = forms.ChoiceField(
|
||||
label=_('Action choice'),
|
||||
@@ -339,11 +339,11 @@ class EventRuleForm(NetBoxModelForm):
|
||||
action_choice = self.cleaned_data.get('action_choice')
|
||||
# Webhook
|
||||
if self.cleaned_data.get('action_type') == EventRuleActionChoices.WEBHOOK:
|
||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(action_choice)
|
||||
self.cleaned_data['action_object_type'] = ObjectType.objects.get_for_model(action_choice)
|
||||
self.cleaned_data['action_object_id'] = action_choice.id
|
||||
# Script
|
||||
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
|
||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(
|
||||
self.cleaned_data['action_object_type'] = ObjectType.objects.get_for_model(
|
||||
Script,
|
||||
for_concrete_model=False
|
||||
)
|
||||
@@ -356,7 +356,7 @@ class TagForm(forms.ModelForm):
|
||||
slug = SlugField()
|
||||
object_types = ContentTypeMultipleChoiceField(
|
||||
label=_('Object types'),
|
||||
queryset=ContentType.objects.with_feature('tags'),
|
||||
queryset=ObjectType.objects.with_feature('tags'),
|
||||
required=False
|
||||
)
|
||||
|
||||
|
@@ -5,7 +5,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from extras.choices import *
|
||||
from ..querysets import ObjectChangeQuerySet
|
||||
|
||||
@@ -113,7 +113,7 @@ class ObjectChange(models.Model):
|
||||
super().clean()
|
||||
|
||||
# Validate the assigned object type
|
||||
if self.changed_object_type not in ContentType.objects.with_feature('change_logging'):
|
||||
if self.changed_object_type not in ObjectType.objects.with_feature('change_logging'):
|
||||
raise ValidationError(
|
||||
_("Change logging is not supported for this object type ({type}).").format(
|
||||
type=self.changed_object_type
|
||||
|
@@ -12,7 +12,7 @@ from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from extras.choices import *
|
||||
from extras.data import CHOICE_SETS
|
||||
from netbox.models import ChangeLoggedModel
|
||||
@@ -52,7 +52,7 @@ class CustomFieldManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
||||
"""
|
||||
Return all CustomFields assigned to the given model.
|
||||
"""
|
||||
content_type = ContentType.objects.get_for_model(model._meta.concrete_model)
|
||||
content_type = ObjectType.objects.get_for_model(model._meta.concrete_model)
|
||||
return self.get_queryset().filter(content_types=content_type)
|
||||
|
||||
def get_defaults_for_model(self, model):
|
||||
|
@@ -12,7 +12,7 @@ from django.utils.formats import date_format
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.utils.encoders import JSONEncoder
|
||||
|
||||
from core.models import ContentType
|
||||
from core.models import ObjectType
|
||||
from extras.choices import *
|
||||
from extras.conditions import ConditionSet
|
||||
from extras.constants import *
|
||||
@@ -646,7 +646,7 @@ class ImageAttachment(ChangeLoggedModel):
|
||||
super().clean()
|
||||
|
||||
# Validate the assigned object type
|
||||
if self.content_type not in ContentType.objects.with_feature('image_attachments'):
|
||||
if self.content_type not in ObjectType.objects.with_feature('image_attachments'):
|
||||
raise ValidationError(
|
||||
_("Image attachments cannot be assigned to this object type ({type}).").format(type=self.content_type)
|
||||
)
|
||||
@@ -739,7 +739,7 @@ class JournalEntry(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ExportTemplat
|
||||
super().clean()
|
||||
|
||||
# Validate the assigned object type
|
||||
if self.assigned_object_type not in ContentType.objects.with_feature('journaling'):
|
||||
if self.assigned_object_type not in ObjectType.objects.with_feature('journaling'):
|
||||
raise ValidationError(
|
||||
_("Journaling is not supported for this object type ({type}).").format(type=self.assigned_object_type)
|
||||
)
|
||||
@@ -795,7 +795,7 @@ class Bookmark(models.Model):
|
||||
super().clean()
|
||||
|
||||
# Validate the assigned object type
|
||||
if self.object_type not in ContentType.objects.with_feature('bookmarks'):
|
||||
if self.object_type not in ObjectType.objects.with_feature('bookmarks'):
|
||||
raise ValidationError(
|
||||
_("Bookmarks cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
||||
)
|
||||
|
Reference in New Issue
Block a user