Răsfoiți Sursa

Closes #15547: Add comments field to CustomField model

Jeremy Stretch 1 an în urmă
părinte
comite
0f0ab1a3be

+ 1 - 1
netbox/extras/api/serializers_/customfields.py

@@ -65,7 +65,7 @@ class CustomFieldSerializer(ValidatedModelSerializer):
             'id', 'url', 'display', 'object_types', 'type', 'related_object_type', 'data_type', 'name', 'label',
             'id', 'url', 'display', 'object_types', 'type', 'related_object_type', 'data_type', 'name', 'label',
             'group_name', 'description', 'required', 'search_weight', 'filter_logic', 'ui_visible', 'ui_editable',
             'group_name', 'description', 'required', 'search_weight', 'filter_logic', 'ui_visible', 'ui_editable',
             'is_cloneable', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
             'is_cloneable', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
-            'choice_set', 'created', 'last_updated',
+            'choice_set', 'comments', 'created', 'last_updated',
         ]
         ]
         brief_fields = ('id', 'url', 'display', 'name', 'description')
         brief_fields = ('id', 'url', 'display', 'name', 'description')
 
 

+ 2 - 1
netbox/extras/filtersets.py

@@ -165,7 +165,8 @@ class CustomFieldFilterSet(ChangeLoggedModelFilterSet):
             Q(name__icontains=value) |
             Q(name__icontains=value) |
             Q(label__icontains=value) |
             Q(label__icontains=value) |
             Q(group_name__icontains=value) |
             Q(group_name__icontains=value) |
-            Q(description__icontains=value)
+            Q(description__icontains=value) |
+            Q(comments__icontains=value)
         )
         )
 
 
 
 

+ 3 - 6
netbox/extras/forms/bulk_edit.py

@@ -5,7 +5,7 @@ from extras.choices import *
 from extras.models import *
 from extras.models import *
 from netbox.forms import NetBoxModelBulkEditForm
 from netbox.forms import NetBoxModelBulkEditForm
 from utilities.forms import BulkEditForm, add_blank_choice
 from utilities.forms import BulkEditForm, add_blank_choice
-from utilities.forms.fields import ColorField, DynamicModelChoiceField
+from utilities.forms.fields import ColorField, CommentField, DynamicModelChoiceField
 from utilities.forms.widgets import BulkEditNullBooleanSelect
 from utilities.forms.widgets import BulkEditNullBooleanSelect
 
 
 __all__ = (
 __all__ = (
@@ -64,6 +64,7 @@ class CustomFieldBulkEditForm(BulkEditForm):
         required=False,
         required=False,
         widget=BulkEditNullBooleanSelect()
         widget=BulkEditNullBooleanSelect()
     )
     )
+    comments = CommentField()
 
 
     nullable_fields = ('group_name', 'description', 'choice_set')
     nullable_fields = ('group_name', 'description', 'choice_set')
 
 
@@ -316,8 +317,4 @@ class JournalEntryBulkEditForm(BulkEditForm):
         choices=add_blank_choice(JournalEntryKindChoices),
         choices=add_blank_choice(JournalEntryKindChoices),
         required=False
         required=False
     )
     )
-    comments = forms.CharField(
-        label=_('Comments'),
-        required=False,
-        widget=forms.Textarea()
-    )
+    comments = CommentField()

+ 1 - 1
netbox/extras/forms/bulk_import.py

@@ -71,7 +71,7 @@ class CustomFieldImportForm(CSVModelForm):
         fields = (
         fields = (
             'name', 'label', 'group_name', 'type', 'object_types', 'related_object_type', 'required', 'description',
             'name', 'label', 'group_name', 'type', 'object_types', 'related_object_type', 'required', 'description',
             'search_weight', 'filter_logic', 'default', 'choice_set', 'weight', 'validation_minimum',
             'search_weight', 'filter_logic', 'default', 'choice_set', 'weight', 'validation_minimum',
-            'validation_maximum', 'validation_regex', 'ui_visible', 'ui_editable', 'is_cloneable',
+            'validation_maximum', 'validation_regex', 'ui_visible', 'ui_editable', 'is_cloneable', 'comments',
         )
         )
 
 
 
 

+ 1 - 0
netbox/extras/forms/model_forms.py

@@ -53,6 +53,7 @@ class CustomFieldForm(forms.ModelForm):
         queryset=CustomFieldChoiceSet.objects.all(),
         queryset=CustomFieldChoiceSet.objects.all(),
         required=False
         required=False
     )
     )
+    comments = CommentField()
 
 
     fieldsets = (
     fieldsets = (
         FieldSet(
         FieldSet(

+ 18 - 0
netbox/extras/migrations/0114_customfield_add_comments.py

@@ -0,0 +1,18 @@
+# Generated by Django 5.0.3 on 2024-04-19 18:37
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0113_customfield_rename_object_type'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='customfield',
+            name='comments',
+            field=models.TextField(blank=True),
+        ),
+    ]

+ 4 - 0
netbox/extras/models/customfields.py

@@ -205,6 +205,10 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
         verbose_name=_('is cloneable'),
         verbose_name=_('is cloneable'),
         help_text=_('Replicate this value when cloning objects')
         help_text=_('Replicate this value when cloning objects')
     )
     )
+    comments = models.TextField(
+        verbose_name=_('comments'),
+        blank=True
+    )
 
 
     objects = CustomFieldManager()
     objects = CustomFieldManager()
 
 

+ 12 - 0
netbox/extras/search.py

@@ -2,6 +2,18 @@ from netbox.search import SearchIndex, register_search
 from . import models
 from . import models
 
 
 
 
+@register_search
+class CustomFieldIndex(SearchIndex):
+    model = models.CustomField
+    fields = (
+        ('name', 100),
+        ('label', 100),
+        ('description', 500),
+        ('comments', 5000),
+    )
+    display_attrs = ('description',)
+
+
 @register_search
 @register_search
 class JournalEntryIndex(SearchIndex):
 class JournalEntryIndex(SearchIndex):
     model = models.JournalEntry
     model = models.JournalEntry

+ 1 - 1
netbox/extras/tables/tables.py

@@ -78,7 +78,7 @@ class CustomFieldTable(NetBoxTable):
         fields = (
         fields = (
             'pk', 'id', 'name', 'object_types', 'label', 'type', 'related_object_type', 'group_name', 'required',
             'pk', 'id', 'name', 'object_types', 'label', 'type', 'related_object_type', 'group_name', 'required',
             'default', 'description', 'search_weight', 'filter_logic', 'ui_visible', 'ui_editable', 'is_cloneable',
             'default', 'description', 'search_weight', 'filter_logic', 'ui_visible', 'ui_editable', 'is_cloneable',
-            'weight', 'choice_set', 'choices', 'created', 'last_updated',
+            'weight', 'choice_set', 'choices', 'comments', 'created', 'last_updated',
         )
         )
         default_columns = ('pk', 'name', 'object_types', 'label', 'group_name', 'type', 'required', 'description')
         default_columns = ('pk', 'name', 'object_types', 'label', 'group_name', 'type', 'required', 'description')
 
 

+ 1 - 0
netbox/templates/extras/customfield.html

@@ -85,6 +85,7 @@
         </tr>
         </tr>
       </table>
       </table>
     </div>
     </div>
+    {% include 'inc/panels/comments.html' %}
     {% plugin_left_page object %}
     {% plugin_left_page object %}
 	</div>
 	</div>
 	<div class="col col-md-6">
 	<div class="col col-md-6">