diff --git a/AUTHORS b/AUTHORS index 1e56bd3412..5d2a1b9fcd 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 b7d6e93def..f7b9069cce 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 53bbadbfd4..375859c897 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() + """}