This should answer your question:

class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)

 If you define a __unicode__() method on your model and not a
__str__()<https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.__str__>method,
Django will automatically provide you with a
__str__()<https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.__str__>that
calls
__unicode__() and then converts the result correctly to a UTF-8 encoded
string object. This is recommended development practice: define only
__unicode__() and let Django take care of the conversion to string objects
when required.


https://docs.djangoproject.com/en/dev/ref/unicode/#choosing-between-str-and-unicode


On Thu, May 17, 2012 at 11:23 AM, Elim Qiu <elim....@gmail.com> wrote:

> In the tutorial poll app, we have models.py like
>
> from django.db import models
>
> # Create your models here.
>
> class Poll(models.Model):
>     question = models.CharField(max_length=200)
>     pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>     poll = models.ForeignKey(Poll)
>     choice = models.CharField(max_length=200)
>     votes = models.IntegerField()
>
> But how to specify utf8 for columns like 'choice', 'question' here?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to