Defer compilation of choices for object_types

This commit is contained in:
Jeremy Stretch 2025-07-31 11:38:11 -04:00
parent 5cf8dc44ba
commit 5d08a80c9e

View File

@ -272,15 +272,19 @@ class GroupForm(forms.ModelForm):
return instance return instance
def get_object_types_choices():
return [
(ot.pk, str(ot))
for ot in ObjectType.objects.filter(OBJECTPERMISSION_OBJECT_TYPES).order_by('app_label', 'model')
]
class ObjectPermissionForm(forms.ModelForm): class ObjectPermissionForm(forms.ModelForm):
object_types = ContentTypeMultipleChoiceField( object_types = ContentTypeMultipleChoiceField(
label=_('Object types'), label=_('Object types'),
queryset=ObjectType.objects.all(), queryset=ObjectType.objects.all(),
widget=SplitMultiSelectWidget( widget=SplitMultiSelectWidget(
choices=[ choices=get_object_types_choices
(ot.pk, str(ot))
for ot in ObjectType.objects.filter(OBJECTPERMISSION_OBJECT_TYPES).order_by('app_label', 'model')
]
), ),
help_text=_('Select the types of objects to which the permission will appy.') help_text=_('Select the types of objects to which the permission will appy.')
) )