On Fri, 2008-12-12 at 09:50 -0500, Karen Tracey wrote:
> On Fri, Dec 12, 2008 at 7:33 AM, ben852 <[email protected]> wrote:
>         
>         Hi,
>         I am new to django and programming.
>         I have a problem with the method _str_( ).
>         Following the tutorial, I edited my models.py file in
>         mysite/books and
>         wrote:
>         [snip]
> 
> The fact that you are using __str__ instead of __unicode__ indicates
> you are using a very old release of Django.  If you are just starting
> out you should really start with the latest 1.0.2 release, it is a
> much better base to learn and build on, with many significant feature
> additions, countless bugs fixed, and API stability.

I hate to write this, since it will no doubt complicate the situation,
but ...

Whilst using __unicode__ is preferable in some respects (will certainly
lead to neater code), Django also handles using __str__ in models. The
developer is responsible for ensuring that __str__ returns UTF-8 encoded
"str" objects, but it's actually the __str__ method that is called in a
lot of cases. Internally, the default Model.__str__ checks for a
__unicode__ method and calls that, encoding the output as UTF-8. So
using __str__ isn't illegal or anything -- but the original poster's
code will fail as written the first time somebody uses non-ASCII
characters in their name, since it's not encoding the output.

Regards,
Malcolm

> 


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

Reply via email to