Skip to content

Commit 5d08a80

Browse files
committed
Defer compilation of choices for object_types
1 parent 5cf8dc4 commit 5d08a80

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

netbox/users/forms/model_forms.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,19 @@ def save(self, *args, **kwargs):
272272
return instance
273273

274274

275+
def get_object_types_choices():
276+
return [
277+
(ot.pk, str(ot))
278+
for ot in ObjectType.objects.filter(OBJECTPERMISSION_OBJECT_TYPES).order_by('app_label', 'model')
279+
]
280+
281+
275282
class ObjectPermissionForm(forms.ModelForm):
276283
object_types = ContentTypeMultipleChoiceField(
277284
label=_('Object types'),
278285
queryset=ObjectType.objects.all(),
279286
widget=SplitMultiSelectWidget(
280-
choices=[
281-
(ot.pk, str(ot))
282-
for ot in ObjectType.objects.filter(OBJECTPERMISSION_OBJECT_TYPES).order_by('app_label', 'model')
283-
]
287+
choices=get_object_types_choices
284288
),
285289
help_text=_('Select the types of objects to which the permission will appy.')
286290
)

0 commit comments

Comments
 (0)