Ticket #5448: primary_unicode.diff

File primary_unicode.diff, 1.5 KB (added by Maciej Wiśniowski, 12 years ago)

Patch against revision 6193

  • django/db/models/base.py

     
    1212from django.dispatch import dispatcher
    1313from django.utils.datastructures import SortedDict
    1414from django.utils.functional import curry
    15 from django.utils.encoding import smart_str, force_unicode
     15from django.utils.encoding import smart_str, force_unicode, smart_unicode
    1616from django.conf import settings
    1717from itertools import izip
    1818import types
     
    213213        pk_val = self._get_pk_val()
    214214        # Note: the comparison with '' is required for compatibility with
    215215        # oldforms-style model creation.
    216         pk_set = pk_val is not None and pk_val != u''
     216        pk_set = pk_val is not None and smart_unicode(pk_val) != u''
    217217        record_exists = True
    218218        if pk_set:
    219219            # Determine whether a record with the primary key already exists.
  • tests/modeltests/custom_pk/models.py

     
     1# -*- coding: utf-8 -*-
    12"""
    2314. Using a custom primary key
    34
     
    9293>>> Business.objects.filter(employees__first_name__startswith='Fran')
    9394[<Business: Sears>]
    9495
     96# Primary key may be unicode string
     97>>> emp = Employee(employee_code='jaźń')
     98>>> emp.save()
     99
    95100"""}
Back to Top