Commits

Matthew Schinckel committed c0d30fc

Allow for _attribute to return as attribute in key names.
Get api_model attributes before model attributes. (May not work?).

  • Participants
  • Parent commits 803ffa6

Comments (0)

Files changed (1)

File rest_api/serializers/json.py

             }
             for field in fields:
                 try:
-                    temp = getattr(obj, field, None)
-                    if api_model:
-                        if getattr(api_model, field, None):
-                            temp = getattr(api_model, field)(obj)
+                    if api_model and getattr(api_model, field, None):
+                        temp = getattr(api_model, field)(obj)
+                    else:
+                        temp = getattr(obj, field, None)
                 except ObjectDoesNotExist:
                     temp = None
                 if api_model and field in api_model.embed_objects:
                 # Not sure if this test should be here. Do we want to
                 # exclude extra fields if they are null?
                 if temp is not None or (api_model and field not in api_model.extra_fields):
+                    if field[0] == "_":
+                        field = field[1:]
                     this[field] = temp
             data.append(this)
         if single: