mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 17:23:15 +00:00
first pass at to_python and get_prep_value on PageChooserBlock
This commit is contained in:
parent
19b13a090a
commit
34bd4bd974
1 changed files with 17 additions and 0 deletions
|
|
@ -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
|
||||
# =======
|
||||
|
|
|
|||
Loading…
Reference in a new issue