22from django .utils .translation import gettext_lazy as _
33from extras .choices import CustomFieldTypeChoices
44from extras .forms import CustomFieldForm
5- from netbox .forms import NetBoxModelForm , NetBoxModelBulkEditForm , NetBoxModelImportForm
6-
7- from utilities .forms .fields import CommentField , ContentTypeChoiceField , DynamicModelChoiceField
5+ from netbox .forms import (NetBoxModelBulkEditForm , NetBoxModelFilterSetForm ,
6+ NetBoxModelForm , NetBoxModelImportForm )
7+ from utilities .forms .fields import (CommentField , ContentTypeChoiceField ,
8+ DynamicModelChoiceField , TagFilterField )
89from utilities .forms .rendering import FieldSet
910from utilities .object_types import object_type_name
1011
1112from netbox_custom_objects .constants import APP_LABEL
12- from netbox_custom_objects .models import CustomObjectObjectType , CustomObjectType , CustomObjectTypeField
13+ from netbox_custom_objects .models import (CustomObjectObjectType ,
14+ CustomObjectType ,
15+ CustomObjectTypeField )
1316
1417__all__ = (
1518 "CustomObjectTypeForm" ,
19+ "CustomObjectTypeBulkEditForm" ,
20+ "CustomObjectTypeImportForm" ,
21+ "CustomObjectTypeFilterForm" ,
1622 "CustomObjectTypeFieldForm" ,
1723 "CustomObjectType" ,
1824)
@@ -33,18 +39,15 @@ class Meta:
3339
3440class CustomObjectTypeBulkEditForm (NetBoxModelBulkEditForm ):
3541 description = forms .CharField (
36- label = _ ('Description' ),
37- max_length = 200 ,
38- required = False
42+ label = _ ("Description" ), max_length = 200 , required = False
3943 )
4044 comments = CommentField ()
4145
4246 model = CustomObjectType
43- fieldsets = (
44- FieldSet ('description' ),
45- )
47+ fieldsets = (FieldSet ("description" ),)
4648 nullable_fields = (
47- 'description' , 'comments' ,
49+ "description" ,
50+ "comments" ,
4851 )
4952
5053
@@ -53,18 +56,29 @@ class CustomObjectTypeImportForm(NetBoxModelImportForm):
5356 class Meta :
5457 model = CustomObjectType
5558 fields = (
56- 'name' , 'description' , 'comments' , 'tags' ,
59+ "name" ,
60+ "description" ,
61+ "comments" ,
62+ "tags" ,
5763 )
5864
5965
66+ class CustomObjectTypeFilterForm (NetBoxModelFilterSetForm ):
67+ model = CustomObjectType
68+ fieldsets = (FieldSet ("q" , "filter_id" , "tag" ),)
69+ tag = TagFilterField (model )
70+
71+
6072class CustomContentTypeChoiceField (ContentTypeChoiceField ):
6173
6274 def label_from_instance (self , obj ):
6375 if obj .app_label == APP_LABEL :
6476 custom_object_type_id = obj .model .replace ("table" , "" ).replace ("model" , "" )
6577 if custom_object_type_id .isdigit ():
6678 try :
67- return CustomObjectType .get_content_type_label (custom_object_type_id )
79+ return CustomObjectType .get_content_type_label (
80+ custom_object_type_id
81+ )
6882 except CustomObjectType .DoesNotExist :
6983 pass
7084 try :
0 commit comments