Skip to content

Commit 81a1c7f

Browse files
committed
#86 add bulk edit, import to CustomObjectType
1 parent 11ce9f5 commit 81a1c7f

File tree

7 files changed

+202
-70
lines changed

7 files changed

+202
-70
lines changed

netbox_custom_objects/filtersets.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
from django.db.models import Q
21
from netbox.filtersets import NetBoxModelFilterSet
32

4-
from .models import CustomObject
3+
from .models import CustomObjectType
54

6-
__all__ = ("CustomObjectFilterSet",)
5+
__all__ = ("CustomObjectTypeFilterSet",)
76

87

8+
class CustomObjectTypeFilterSet(NetBoxModelFilterSet):
9+
class Meta:
10+
model = CustomObjectType
11+
fields = (
12+
"id",
13+
"name",
14+
)
15+
16+
17+
"""
918
class CustomObjectFilterSet(NetBoxModelFilterSet):
1019
class Meta:
1120
model = CustomObject
@@ -19,3 +28,4 @@ def search(self, queryset, name, value):
1928
if not value.strip():
2029
return queryset
2130
return queryset.filter(Q(name__icontains=value))
31+
"""

netbox_custom_objects/forms.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from django.utils.translation import gettext_lazy as _
33
from extras.choices import CustomFieldTypeChoices
44
from extras.forms import CustomFieldForm
5-
from netbox.forms import NetBoxModelForm
5+
from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelImportForm
6+
67
from utilities.forms.fields import CommentField, ContentTypeChoiceField, DynamicModelChoiceField
78
from utilities.forms.rendering import FieldSet
89
from utilities.object_types import object_type_name
@@ -30,6 +31,32 @@ class Meta:
3031
fields = ("name", "verbose_name_plural", "description", "comments", "tags")
3132

3233

34+
class CustomObjectTypeBulkEditForm(NetBoxModelBulkEditForm):
35+
description = forms.CharField(
36+
label=_('Description'),
37+
max_length=200,
38+
required=False
39+
)
40+
comments = CommentField()
41+
42+
model = CustomObjectType
43+
fieldsets = (
44+
FieldSet('description'),
45+
)
46+
nullable_fields = (
47+
'description', 'comments',
48+
)
49+
50+
51+
class CustomObjectTypeImportForm(NetBoxModelImportForm):
52+
53+
class Meta:
54+
model = CustomObjectType
55+
fields = (
56+
'name', 'description', 'comments', 'tags',
57+
)
58+
59+
3360
class CustomContentTypeChoiceField(ContentTypeChoiceField):
3461

3562
def label_from_instance(self, obj):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.2 on 2025-07-24 18:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("netbox_custom_objects", "0003_delete_customobject"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="customobjecttype",
15+
name="comments",
16+
field=models.TextField(blank=True),
17+
),
18+
]

0 commit comments

Comments
 (0)