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 <eventel...@gmail.com> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CALn3ei3uvS62R3Aju350frKQJZhHSkK8S1qiLTxq6q%3DJeSBg6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to