FAQ
Hola,

I'm using a standard view function to retrieve all details about an object:

     header =[]
     headers = object._meta.get_all_field_names()
     row = []
     for field in headers:
         value = getattr(object, field)
     row.append(value)

to collect info on a particular object passed to a view.

I was wondering how I might exclude the unicode markings on a test
field (eg: u'text' ) from the output? IE, get rid of all the leading
u's. I could just strip/slice but I presume there is a less clunky
way?

cheers
L.

--
Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
When you used to be punk, and now you are still punk but not as punk,
are you post-punk or decaying punk or ex-punk or just not punk anymore

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Valder Gallo at Sep 23, 2013 at 12:47 pm
    Sorry, i really don´t understand why you need this.

    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())


    Other projects to export CSV.

    https://github.com/valdergallo/data-importer
    https://pypi.python.org/pypi/django-export
    https://docs.djangoproject.com/en/dev/howto/outputting-csv/




    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman wrote:

    Hola,

    I'm using a standard view function to retrieve all details about an object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Lachlan Musicman at Sep 23, 2013 at 7:01 pm

    On 23 September 2013 22:47, Valder Gallo wrote:
    Sorry, i really don´t understand why you need this.
    To mail merge details taken in web app into a report.
    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())
    Thanks! Very succinct.

    L.





    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman wrote:

    Hola,

    I'm using a standard view function to retrieve all details about an
    object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Valder Gallo at Sep 23, 2013 at 2:43 pm
    :D


    On Mon, Sep 23, 2013 at 10:12 AM, Lachlan Musicman wrote:
    On 23 September 2013 22:47, Valder Gallo wrote:
    Sorry, i really don´t understand why you need this.
    To mail merge details taken in web app into a report.
    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())
    Thanks! Very succinct.

    L.





    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman wrote:

    Hola,

    I'm using a standard view function to retrieve all details about an
    object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Lachlan Musicman at Sep 23, 2013 at 9:47 pm
    Ok, so here's the challenging part - how would you get the
    get_FOO_display value for some but not all of those values?

    cheers
    L.
    On 23 September 2013 23:29, Valder Gallo wrote:
    :D


    On Mon, Sep 23, 2013 at 10:12 AM, Lachlan Musicman wrote:
    On 23 September 2013 22:47, Valder Gallo wrote:
    Sorry, i really don´t understand why you need this.
    To mail merge details taken in web app into a report.
    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())
    Thanks! Very succinct.

    L.






    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman <datakid@gmail.com>
    wrote:
    Hola,

    I'm using a standard view function to retrieve all details about an
    object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.
  • C. Kirby at Sep 23, 2013 at 10:29 pm
    try:
             value = getattr(object, 'get_%s_display' % field)()
         except:
             value getattr(object, field)
    On Monday, September 23, 2013 4:47:33 PM UTC-5, Lachlan Musicman wrote:

    Ok, so here's the challenging part - how would you get the
    get_FOO_display value for some but not all of those values?

    cheers
    L.

    On 23 September 2013 23:29, Valder Gallo <valde...@gmail.com <javascript:>>
    wrote:
    :D



    On Mon, Sep 23, 2013 at 10:12 AM, Lachlan Musicman <dat...@gmail.com<javascript:>>
    wrote:
    On 23 September 2013 22:47, Valder Gallo wrote:
    Sorry, i really don´t understand why you need this.
    To mail merge details taken in web app into a report.
    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())
    Thanks! Very succinct.

    L.






    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman <dat...@gmail.com<javascript:>>
    wrote:
    Hola,

    I'm using a standard view function to retrieve all details about an
    object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as
    punk,
    are you post-punk or decaying punk or ex-punk or just not punk
    anymore
    --
    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...@googlegroups.com <javascript:>.
    To post to this group, send email to django...@googlegroups.com<javascript:>.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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...@googlegroups.com <javascript:>.
    To post to this group, send email to django...@googlegroups.com<javascript:>.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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...@googlegroups.com <javascript:>.
    To post to this group, send email to django...@googlegroups.com<javascript:>.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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...@googlegroups.com <javascript:>.
    To post to this group, send email to django...@googlegroups.com<javascript:>.
    Visit this group at http://groups.google.com/group/django-users.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore
    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.
  • C. Kirby at Sep 23, 2013 at 10:31 pm
    Whoops, missed the map step.
    I think you will need to create a new dict using the try/except above, and
    then map the new dict to str
    On Monday, September 23, 2013 5:29:40 PM UTC-5, C. Kirby wrote:

    try:
    value = getattr(object, 'get_%s_display' % field)()
    except:
    value getattr(object, field)
    On Monday, September 23, 2013 4:47:33 PM UTC-5, Lachlan Musicman wrote:

    Ok, so here's the challenging part - how would you get the
    get_FOO_display value for some but not all of those values?

    cheers
    L.
    On 23 September 2013 23:29, Valder Gallo wrote:
    :D



    On Mon, Sep 23, 2013 at 10:12 AM, Lachlan Musicman <dat...@gmail.com>
    wrote:
    On 23 September 2013 22:47, Valder Gallo wrote:
    Sorry, i really don´t understand why you need this.
    To mail merge details taken in web app into a report.
    If you just wanna convert one object in a list string.

    map(str, object.__dict__.values())
    Thanks! Very succinct.

    L.






    On Mon, Sep 23, 2013 at 2:56 AM, Lachlan Musicman <dat...@gmail.com>
    wrote:
    Hola,

    I'm using a standard view function to retrieve all details about an
    object:

    header =[]
    headers = object._meta.get_all_field_names()
    row = []
    for field in headers:
    value = getattr(object, field)
    row.append(value)

    to collect info on a particular object passed to a view.

    I was wondering how I might exclude the unicode markings on a test
    field (eg: u'text' ) from the output? IE, get rid of all the
    leading
    u's. I could just strip/slice but I presume there is a less clunky
    way?

    cheers
    L.

    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as
    punk,
    are you post-punk or decaying punk or ex-punk or just not punk
    anymore
    --
    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...@googlegroups.com.
    To post to this group, send email to django...@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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...@googlegroups.com.
    To post to this group, send email to django...@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore

    --
    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...@googlegroups.com.
    To post to this group, send email to django...@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    Valder Gallo
    +55 11 9949 2911
    +55 11 2532 2911
    Skype: valdergallo
    @valdergallo
    www.valdergallo.com.br

    --
    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...@googlegroups.com.
    To post to this group, send email to django...@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013:
    When you used to be punk, and now you are still punk but not as punk,
    are you post-punk or decaying punk or ex-punk or just not punk anymore
    --
    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+unsubscribe@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.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedSep 23, '13 at 5:56a
activeSep 23, '13 at 10:31p
posts7
users3
websitedjangoproject.com

People

Translate

site design / logo © 2022 Grokbase