first pass at to_python and get_prep_value on PageChooserBlock

This commit is contained in:
Matt Westcott 2015-02-10 23:29:20 +00:00
parent 19b13a090a
commit 34bd4bd974

View file

@ -356,6 +356,23 @@ class PageChooserBlock(FieldBlock):
from wagtail.wagtailadmin.widgets import AdminPageChooser
return ModelChoiceField(queryset=Page.objects.all(), widget=AdminPageChooser)
def to_python(self, value):
from wagtail.wagtailcore.models import Page
if value is None or isinstance(value, Page):
return value
else:
try:
return Page.objects.get(pk=value) # TODO: use the specific class in place of Page where appropriate
except Page.DoesNotExist:
return None
def get_prep_value(self, value):
if isinstance(value, Page):
return value.id
else:
return value
# =======
# Chooser
# =======