Thanks Vijay,
since this is a very small application, it uses sqlite 3 as the data
backend... according to http://www.sqlite.org/lang_corefunc.html, there is
a trim() function in sqlite... so I will check if this works.
best
Thomas
Am Dienstag, 3. November 2015 14:02:52 UTC+1 schrieb Vijay Khemlani:
>
> As far as I know the Django ORM encapsulates SQL queries, so you can't put
> arbitrary python code in there (".strip()")
>
> If I remember correctly SQL does not have a standard TRIM method, but
> individual database engines do, for example for Postgres
>
> http://www.postgresql.org/docs/9.1/static/functions-string.html
>
> So you can run a raw SQL command or just iterate over all the rows in your
> data I think.
>
> On Tue, Nov 3, 2015 at 6:57 AM, DJ-Tom <[email protected] <javascript:>>
> wrote:
>
>> Hi,
>>
>> I have several character fields with leading and trailing spaces and
>> would like to know if it is possible to clean them up with a one-liner...
>>
>> I tried the following but none of this works:
>>
>>
>> rooms.objects.all().update(name=F('name').strip()) // AttributeError: 'F'
>> object has no attribute 'strip'
>>
>> rooms.objects.all().update(name=Value(F('name')).strip()) //
>> AttributeError: 'Value' object has no attribute 'strip'
>>
>> rooms.objects.all().update(name=name.strip()) // NameError: name 'name' is
>> not defined
>>
>> Also searching via Google did not help.
>>
>> Of course I could do some loop, but this seems to be not very efficient to
>> me.
>>
>> Any Idea?
>>
>> Thomas
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f018f0a5-3a8a-4c28-a1d6-2fb96807093e%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/django-users/f018f0a5-3a8a-4c28-a1d6-2fb96807093e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/55d12dc5-dd7f-41f1-8141-24ccf759ed6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.