Commit 253663ae by Alen Mujezinovic

Added possibility to specify what attributes of ForeignKeys and OneToOne fields…

Added possibility to specify what attributes of ForeignKeys and OneToOne fields to include via nested tuples
parent c7c14088
...@@ -62,6 +62,12 @@ def _model_to_dict(instance, resource=None): ...@@ -62,6 +62,12 @@ def _model_to_dict(instance, resource=None):
# Method fields # Method fields
for fname in extra_fields: for fname in extra_fields:
if isinstance(fname, (tuple, list)):
fname, fields = fname
else:
fname, fields = fname, False
try: try:
if hasattr(resource, fname): if hasattr(resource, fname):
# check the resource first, to allow it to override fields # check the resource first, to allow it to override fields
...@@ -77,7 +83,13 @@ def _model_to_dict(instance, resource=None): ...@@ -77,7 +83,13 @@ def _model_to_dict(instance, resource=None):
# TODO: It would be nicer if this didn't recurse here. # TODO: It would be nicer if this didn't recurse here.
# Let's keep _model_to_dict flat, and _object_to_data recursive. # Let's keep _model_to_dict flat, and _object_to_data recursive.
data[fname] = _object_to_data(obj) if fields:
Resource = type('Resource', (object,), {'fields': fields,
'include': (),
'exclude': ()})
data[fname] = _object_to_data(obj, Resource())
else:
data[fname] = _object_to_data(obj)
except NoReverseMatch: except NoReverseMatch:
# Ug, bit of a hack for now # Ug, bit of a hack for now
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment