From 5270c14444b5ada7a60c0b644fcc43d456c10a2d Mon Sep 17 00:00:00 2001 From: alexpilot11 Date: Tue, 19 Jan 2016 17:38:10 -0500 Subject: [PATCH] ChooserBlock should use pk instead of id --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + docs/releases/1.4.rst | 1 + wagtail/wagtailcore/blocks/field_block.py | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f384d913b..65bef00a2 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -10,6 +10,7 @@ Changelog * Fix: Deleting a page content type now preserves existing pages as basic Page instances, to prevent tree corruption * Fix: The `Page.path` field is now explicitly given the "C" collation on PostgreSQL to prevent tree ordering issues when using a database created with the Slovak locale * Fix: Wagtail's compiled static assets are now put into the correct directory on Windows (Aarni Koskela) + * Fix: `ChooserBlock` now correctly handles models with primary keys other than `id` (alexpilot11) 1.3.1 (05.01.2016) ~~~~~~~~~~~~~~~~~~ diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 546f707a1..d7face344 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -96,6 +96,7 @@ Contributors * benjaoming * Alexander Bogushov * Aarni Koskela +* alexpilot11 Translators diff --git a/docs/releases/1.4.rst b/docs/releases/1.4.rst index 7c6668314..cb7c25993 100644 --- a/docs/releases/1.4.rst +++ b/docs/releases/1.4.rst @@ -27,6 +27,7 @@ Bug fixes * Deleting a page content type now preserves existing pages as basic Page instances, to prevent tree corruption * The ``Page.path`` field is now explicitly given the "C" collation on PostgreSQL to prevent tree ordering issues when using a database created with the Slovak locale * Wagtail's compiled static assets are now put into the correct directory on Windows (Aarni Koskela) + * ``ChooserBlock`` now correctly handles models with primary keys other than ``id`` (alexpilot11) Upgrade considerations diff --git a/wagtail/wagtailcore/blocks/field_block.py b/wagtail/wagtailcore/blocks/field_block.py index b407ac8c5..ea846841d 100644 --- a/wagtail/wagtailcore/blocks/field_block.py +++ b/wagtail/wagtailcore/blocks/field_block.py @@ -353,11 +353,11 @@ class ChooserBlock(FieldBlock): return None def get_prep_value(self, value): - # the native value (a model instance or None) should serialise to an ID or None + # the native value (a model instance or None) should serialise to a PK or None if value is None: return None else: - return value.id + return value.pk def value_from_form(self, value): # ModelChoiceField sometimes returns an ID, and sometimes an instance; we want the instance