最后这是我找到的解决方案:
def content_type_choices(**kwargs):
content_types = []
for content_type in ContentType.objects.filter(**kwargs):
content_types.append((content_type.pk, content_type.model_class()._meta.verbose_name))
return content_types
LIMIT_CHOICES_TO = {'model__startswith': 'pageapp_'}
class PageWAForm(forms.ModelForm):
app_page_type = forms.ModelChoiceField(queryset=ContentType.objects.filter(**LIMIT_CHOICES_TO),
empty_label=None)
def __init__(self, *args, **kwargs):
super(PageWAForm, self).__init__(*args, **kwargs)
self.fields['app_page_type'].choices = content_type_choices(**LIMIT_CHOICES_TO)