On Sat, Apr 13, 2013 at 6:37 AM, mln sastry <[email protected]> wrote:
>
>
> Hi Anshum,
>   Thank you for responding.
>   I defined a Book model as shown below and tried to save it from the admin
> shell.
>   I am using python2.7.3 , django1.5, and python mysql driver 1.2.3.
>   I am not sure if my model data type is wrong or if any qualifier is
> missing. Please help.
>
>   I got this error:Warning: Incorrect string value:
> '\xE0\xA4\xB6\xE0\xA5\x8D...' for column 'bookName' at row 1"
>
> class Book(models.Model):
>
>     bookId = models.AutoField(primary_key=True)
>
>     bookName = models.TextField(max_length=200,null=False,)
>
>     bookShortName = models.CharField(max_length=10,null=True,)
>
>     isDeleted = models.NullBooleanField  (null=True,)
>
>
>
> gita4 = Book(bookName=
> "श्रीमद्भगवद्गीता",bookShortName="गीता",isDeleted=False)

This is not specifying a unicode string, it is specifying a byte
string. A unicode string starts u"Some text". Django correctly handles
unicode text, but if it is given byte strings, what happens depends
upon your environment - mostly, it will just not work.

There is an excellent document describing python 2.x and it's unicode handling:

http://docs.python.org/2/howto/unicode.html

however, the only things you really need to do:

1) Specify unicode strings as unicode by prefixing with u, eg
u"श्रीमद्भगवद्गीता"
2) Any python file that you include non-ascii characters in must
specify the encoding the file is in, by adding a special comment to
either the first or second line in the file:
# -*- coding: utf-8 -*-

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to