Changes between Version 7 and Version 8 of UnicodeBranch
- Timestamp:
- May 12, 2007, 5:14:53 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UnicodeBranch
v7 v8 55 55 A detailed list of things you might wish to think about when writing your code is given below. However, for the programmer on a deadline, here is the cheatsheet version: 56 56 57 1. Make sure your database can store all the data you will send to it. Usually, this means ensuring it is using UTF-8 (or similar) encoding internally.57 1. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed. 58 58 59 2. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed.59 2. Look for any {{{str()}}} calls in your code that operate on model fields. These should almost always be changed to {{{smart_unicode()}}} calls (which is imported from {{{django.utils.encoding}}}). 60 60 61 3. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded. 61 3. Make sure your database can store all the data you will send to it. Usually, this means ensuring it is using UTF-8 (or similar) encoding internally. 62 63 4. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded. 62 64 63 65 That is all. Enjoy! … … 77 79 * Field sizes for text fields such as !TextField and !CharField are specified in terms of characters, not the number of bytes used in the encoding in the database. All databases supported by Django can handle this (i.e. their ''VARCHAR'' fields are sized in terms of characaters and can store unicode characters). So you do '''not''' need to worry about how many bytes the encoded version of your data will take up when working with lengths. 78 80 79 * You might find the functions {{{django.utils.encoding.smart_string()}}} and {{{dhango.utils.encoding.smart_unicode()}}} useful in your application code. Particularly the latter is handy: it takes a bytestring or unicode string and returns a unicode string. It also knows to convert objects with a {{{__unicode___}} method into unicode strings. So if you have a string that is either a bytestring or unicode and you wish to make it uniform -- always a unicode string -- call {{{smart_unicode()}}} on the object.81 * You might find the functions {{{django.utils.encoding.smart_string()}}} and {{{dhango.utils.encoding.smart_unicode()}}} useful in your application code. Particularly the latter is handy: it takes a bytestring or unicode string and returns a unicode string. It also knows to convert objects with a {{{__unicode___}}} or {{{__str__}}} method into unicode strings. So if you have a string that is either a bytestring or unicode and you wish to make it uniform -- always a unicode string -- call {{{smart_unicode()}}} on the object. 80 82 81 83 === Databases ===