class PageFormCategories(forms.ModelForm): class Meta: model = Page def __init__(self, *args, **kwargs): super(PageFormCategories, self).__init__(*args, **kwargs) cat_ct = ContentType.objects.get_for_model(Category) prod_ct = ContentType.objects.get_for_model(Product) self.fields["parent"].queryset = Page.objects.filter(content_type=cat_ct) self.fields["related"].queryset = Page.objects.filter(content_type=prod_ct) class PageFormCategoriesAndSites(forms.ModelForm): class Meta: model = Page def __init__(self, *args, **kwargs): super(PageFormCategoriesAndSites, self).__init__(*args, **kwargs) cat_ct = ContentType.objects.get_for_model(Category) site_ct = ContentType.objects.get_for_model(Site) self.fields["parent"].queryset = Page.objects.filter(Q(content_type=cat_ct) | Q(content_type=site_ct)) self.fields["related"].queryset = Page.objects.get_empty_query_set()