On Thu, Feb 24, 2011 at 5:17 PM, Lee Hinde <leehi...@gmail.com> wrote:
> On Thu, Feb 24, 2011 at 1:32 AM, Tom Evans <tevans...@googlemail.com> wrote:
>> On Wed, Feb 23, 2011 at 9:17 PM, Lee Hinde <leehi...@gmail.com> wrote:
>>> Except, now the data that's in the database for the username field
>>> goes from looking like this:
>>> leehinde
>>> to this
>>> (u'leehinde',)
>>>
>>> I'd like it to be 'leehinde' again
>>> so, clearly objects.create is more clever than my pure post. But I'm
>>> not sure where in the food chain I should be interceding..
>>>
>>
>> http://docs.djangoproject.com/en/1.2/ref/unicode/#general-string-handling
>>
>> """
>> In most cases when Django is dealing with strings, it will convert
>> them to Unicode strings before doing anything else. So, as a general
>> rule, if you pass in a bytestring, be prepared to receive a Unicode
>> string back in the result.
>> """
>>
>> Be prepared :)
>>
>
> Thanks Tom; sadly I'm ill-prepared.
>
> a) It's curious that the two django methods (get_or_create vs create)
> do different things.
> b) I tried wrapping the form fields in str() and got an error, but
> I'll play with that some more and figure out why.
>
> I'd found that page, as I really did google 'django unicode, etc.'
> before posting. :-) but it assumes more python skill than I have this
> week.
>

Why is it curious? get_or_create() does different things to create() -
create() always tries to create a new instance with the attributes you
give it, where as get_or_create() always tries to retrieve an object
with the attributes you give it, and only if that does not exist,
tries to create it.

Accordingly, create() returns an instance of the model, and
get_or_create() returns a 2-tuple of (instance, was_created).

Why would you wrap fields in str()? Just use unicode, you are making
life more difficult for yourself by wanting to coerce everything to
ascii.

Cheers

Tom

-- 
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