File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 66)
77
88APP_LABEL = "netbox_custom_objects"
9+
10+ # Field names that are reserved and cannot be used for custom object fields
11+ RESERVED_FIELD_NAMES = [
12+ "bookmarks" ,
13+ "contacts" ,
14+ "created" ,
15+ "custom_field_data" ,
16+ "id" ,
17+ "images" ,
18+ "jobs" ,
19+ "journal_entries" ,
20+ "last_updated" ,
21+ "pk" ,
22+ "subscriptions" ,
23+ "tags" ,
24+ ]
Original file line number Diff line number Diff line change 4949from utilities .string import title
5050from utilities .validators import validate_regex
5151
52- from netbox_custom_objects .constants import APP_LABEL
52+ from netbox_custom_objects .constants import APP_LABEL , RESERVED_FIELD_NAMES
5353from netbox_custom_objects .field_types import FIELD_TYPE_CLASS
5454
5555
@@ -813,6 +813,16 @@ def related_object_type_label(self):
813813 def clean (self ):
814814 super ().clean ()
815815
816+ # Check if the field name is reserved
817+ if self .name in RESERVED_FIELD_NAMES :
818+ raise ValidationError (
819+ {
820+ "name" : _ (
821+ 'Field name "{name}" is reserved and cannot be used. Reserved names are: {reserved_names}'
822+ ).format (name = self .name , reserved_names = ", " .join (RESERVED_FIELD_NAMES ))
823+ }
824+ )
825+
816826 # Validate the field's default value (if any)
817827 if self .default is not None :
818828 try :
You can’t perform that action at this time.
0 commit comments