Re: readable object

2007-12-12 Thread IdNotFound


Hello,

After you mentioned this on #django, I went on hacking something as I
told you. I'm not sure what are the guidelines in this list for
posting code, so I'll just paste below, since dpaste can vanish
eventually. Please forgive me since this is my first post. Let me know
and it won't happen again ;-))

Check if this is sort of what you had in mind... Currently, it prints
on screen (I was using the shell) but you could of course easily
change that for whatever suits your needs. I haven't tested much, but
seems to work fine with ForeignKey() and ManyToManyField().


== start cutting here ==

#
# you can also find this in... http://dpaste.com/hold/27861/
#

from django.newforms.models import model_to_dict

def model_to_human(model):
d = model_to_dict(model)

for (k, v) in d.items():

try:
# test for relation manager
value = unicode(eval('model.'+k+'.all()'))
except AttributeError:
# nope, not that!

# let's prettify the output Django-style
inst = str(eval('model.'+k+'.__class__'))
fullClass = inst.split(' ')[1][1:-2] # gets ""
splitted = fullClass.split('.')

value = str(eval('model.'+k))
if len(splitted) > 1:
# this is not a builtin type, so we can prettify it
className = splitted[-1] # gets last dotted part
value = '<'+ className +': '+ value +'>'

print str(k) +': '+ value


== end cutting here ==


Hope it helps,
Eduardo "IdNotFound"


On Dec 12, 5:13 pm, Milan Andric <[EMAIL PROTECTED]> wrote:
> Is there an easy way to print an object in html?  Basically with
> display names and manytomany relationships resolved.  (just for
> viewing)
>
> I was thinking to write something like model_to_dict(obj)  that
> resolves a bunch of stuff and makes it more readable.  But returns a
> big html string similar to printing a form but without input fields.
>
> Anything like that exist already?
>
> --
> Milan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: readable object

2007-12-12 Thread Marty Alchin

You might look into databrowse[1], which is available in the SVN
version of Django. There are some screenshots[2] available as well, so
you can like to see what it's like.

-Gul

[1] http://www.djangoproject.com/documentation/databrowse/
[2] 
http://www.flickr.com/photos/ubernostrum/2010704987/in/set-72157603155401014/

On Dec 12, 2007 2:13 PM, Milan Andric <[EMAIL PROTECTED]> wrote:
>
> Is there an easy way to print an object in html?  Basically with
> display names and manytomany relationships resolved.  (just for
> viewing)
>
> I was thinking to write something like model_to_dict(obj)  that
> resolves a bunch of stuff and makes it more readable.  But returns a
> big html string similar to printing a form but without input fields.
>
> Anything like that exist already?
>
> --
> Milan
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: readable object

2007-12-12 Thread Milan Andric



On Dec 12, 1:13 pm, Milan Andric <[EMAIL PROTECTED]> wrote:
> Is there an easy way to print an object in html?  Basically with
> display names and manytomany relationships resolved.  (just for
> viewing)
>
> I was thinking to write something like model_to_dict(obj)  that
> resolves a bunch of stuff and makes it more readable.  But returns a
> big html string similar to printing a form but without input fields.
>
> Anything like that exist already?
>

In case you've never seen model_to_dict() I recently found out about
it from Magus the great on IRC.
http://code.djangoproject.com/browser/django/trunk/django/newforms/models.py#L148

Always asking for more!

TIA --

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: readable object

2007-12-12 Thread shaleh

>On Wed Dec 12 11:13 , Milan Andric <[EMAIL PROTECTED]> wrote:
> Is there an easy way to print an object in html?  Basically with display 
> names and manytomany relationships resolved.  (just for viewing)
> I was thinking to write something like model_to_dict(obj)  that resolves a 
> bunch of stuff and makes it more readable.
> But returns a big html string similar to printing a form but without input 
> fields.  Anything like that exist already?

Have you considered Python's "Pretty Print" module?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---