class PageFormCategories forms ModelForm class Meta model Page def __i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()