From eea935a7f410b6ebda562d3d24d72f2b3fdda4b9 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 14 Sep 2007 18:36:04 +0000 Subject: [PATCH] Fixed #5448: you can now use unicode characters in primary keys. Thanks, pigletto. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6200 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/db/models/base.py | 4 ++-- tests/modeltests/custom_pk/models.py | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1e56bd34120..5d2a1b9fcd1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -232,6 +232,7 @@ answer newbie questions, and generally made Django that much better: phil@produxion.net phil.h.smith@gmail.com Gustavo Picon + pigletto Luke Plant plisk Daniel Poelzleithner diff --git a/django/db/models/base.py b/django/db/models/base.py index b7d6e93def6..f7b9069ccea 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -12,7 +12,7 @@ from django.db.models.loading import register_models, get_model from django.dispatch import dispatcher from django.utils.datastructures import SortedDict from django.utils.functional import curry -from django.utils.encoding import smart_str, force_unicode +from django.utils.encoding import smart_str, force_unicode, smart_unicode from django.conf import settings from itertools import izip import types @@ -213,7 +213,7 @@ class Model(object): pk_val = self._get_pk_val() # Note: the comparison with '' is required for compatibility with # oldforms-style model creation. - pk_set = pk_val is not None and pk_val != u'' + pk_set = pk_val is not None and smart_unicode(pk_val) != u'' record_exists = True if pk_set: # Determine whether a record with the primary key already exists. diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py index 53bbadbfd48..375859c8970 100644 --- a/tests/modeltests/custom_pk/models.py +++ b/tests/modeltests/custom_pk/models.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ 14. Using a custom primary key @@ -92,4 +93,8 @@ DoesNotExist: Employee matching query does not exist. >>> Business.objects.filter(employees__first_name__startswith='Fran') [] +# Primary key may be unicode string +>>> emp = Employee(employee_code='jaźń') +>>> emp.save() + """}