Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
31a73beb
Commit
31a73beb
authored
Jan 04, 2013
by
Sofia Papagiannaki
Browse files
Extend model_to_dict utility to include object
properties and obj string representation
parent
3511df6f
Changes
1
Show whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/util.py
View file @
31a73beb
...
@@ -218,6 +218,9 @@ def get_query(request):
...
@@ -218,6 +218,9 @@ def get_query(request):
except
AttributeError
:
except
AttributeError
:
return
{}
return
{}
def
get_properties
(
obj
):
return
(
i
for
i
in
vars
(
obj
.
__class__
)
\
if
isinstance
(
getattr
(
obj
.
__class__
,
i
),
property
))
def
model_to_dict
(
obj
,
exclude
=
[
'AutoField'
,
'ForeignKey'
,
'OneToOneField'
],
def
model_to_dict
(
obj
,
exclude
=
[
'AutoField'
,
'ForeignKey'
,
'OneToOneField'
],
include_empty
=
True
):
include_empty
=
True
):
...
@@ -265,6 +268,10 @@ def model_to_dict(obj, exclude=['AutoField', 'ForeignKey', 'OneToOneField'],
...
@@ -265,6 +268,10 @@ def model_to_dict(obj, exclude=['AutoField', 'ForeignKey', 'OneToOneField'],
value
=
unicode
(
value
)
if
value
is
not
None
else
value
value
=
unicode
(
value
)
if
value
is
not
None
else
value
if
value
or
include_empty
:
if
value
or
include_empty
:
tree
[
field_name
]
=
value
tree
[
field_name
]
=
value
properties
=
list
(
get_properties
(
obj
))
for
p
in
properties
:
tree
[
p
]
=
getattr
(
obj
,
p
)
tree
[
'str_repr'
]
=
obj
.
__str__
()
return
tree
return
tree
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment