Skip to content

Commit 64f1f33

Browse files
committed
Merge pull request django-cms#3500 from jsma/pagefield-fix
Fixed PageField to work with Django 1.7
2 parents 8a909ee + 223c669 commit 64f1f33

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cms/forms/fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class PageSelectFormField(forms.MultiValueField):
3333
}
3434

3535
def __init__(self, queryset=None, empty_label=u"---------", cache_choices=False,
36-
required=True, widget=None, to_field_name=None, *args, **kwargs):
36+
required=True, widget=None, to_field_name=None, limit_choices_to=None,
37+
*args, **kwargs):
3738
errors = self.default_error_messages.copy()
3839
if 'error_messages' in kwargs:
3940
errors.update(kwargs['error_messages'])
4041
site_choices = SuperLazyIterator(get_site_choices)
4142
page_choices = SuperLazyIterator(get_page_choices)
43+
self.limit_choices_to = limit_choices_to
4244
kwargs['required'] = required
4345
fields = (
4446
LazyChoiceField(choices=site_choices, required=False, error_messages={'invalid': errors['invalid_site']}),

cms/models/fields.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ class PageField(models.ForeignKey):
8383
default_model_class = Page
8484

8585
def __init__(self, **kwargs):
86-
# we call ForeignKey.__init__ with the Page model as parameter...
87-
# a PageField can only be a ForeignKey to a Page
88-
super(PageField, self).__init__(self.default_model_class, **kwargs)
86+
# We hard-code the `to` argument for ForeignKey.__init__
87+
# since a PageField can only be a ForeignKey to a Page
88+
kwargs['to'] = self.default_model_class
89+
super(PageField, self).__init__(**kwargs)
8990

9091
def formfield(self, **kwargs):
9192
defaults = {

0 commit comments

Comments
 (0)