From 6fe80b2a93bed40cd7587fe0c9af9438a2308ced Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 9 Mar 2009 00:07:50 +0000 Subject: [1.0.X] Pass values through get_db_prep_save() in a QuerySet.update() call. This removes a long-standing FIXME in the update() handling and allows for greater flexibility in the values passed in. In particular, it brings updates into line with saves for django.contrib.gis fields, so fixed #10411. Thanks to Justin Bronn and Russell Keith-Magee for help with this patch. Backport of r10003 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10004 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/sql/subqueries.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index 14af34d7c4..1a0197e8f6 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -233,9 +233,10 @@ class UpdateQuery(Query): """ from django.db.models.base import Model for field, model, val in values_seq: - # FIXME: Some sort of db_prep_* is probably more appropriate here. - if field.rel and isinstance(val, Model): - val = val.pk + if hasattr(val, 'prepare_database_save'): + val = val.prepare_database_save(field) + else: + val = field.get_db_prep_save(val) # Getting the placeholder for the field. if hasattr(field, 'get_placeholder'): -- cgit v1.3