aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/relations.py
diff options
context:
space:
mode:
authorCarlton Gibson2015-03-08 20:22:49 +0100
committerCarlton Gibson2015-03-08 20:22:49 +0100
commit53e1a2fcb9643a4a1ea07881ea207e9bbefdf5df (patch)
tree3f642c80e3df19f3a70a01c3501a3a0f74e176c0 /rest_framework/relations.py
parent0e21f1c4f4cd91551cd6021a8ca03a6911feac44 (diff)
parentfb58ef043cc39d900bb8389855f07087cb0d7920 (diff)
downloaddjango-rest-framework-53e1a2fcb9643a4a1ea07881ea207e9bbefdf5df.tar.bz2
Merge pull request #2637 from mdentremont/topic/allow-serialize-unsaved-with-relations
Support serializing unsaved models with related fields.
Diffstat (limited to 'rest_framework/relations.py')
-rw-r--r--rest_framework/relations.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/rest_framework/relations.py b/rest_framework/relations.py
index 0b7c9d86..3a966c5b 100644
--- a/rest_framework/relations.py
+++ b/rest_framework/relations.py
@@ -360,6 +360,10 @@ class ManyRelatedField(Field):
]
def get_attribute(self, instance):
+ # Can't have any relationships if not created
+ if not instance.pk:
+ return []
+
relationship = get_attribute(instance, self.source_attrs)
return relationship.all() if (hasattr(relationship, 'all')) else relationship