diff options
| author | Devon Bleibtrey | 2015-03-23 10:42:42 -0400 | 
|---|---|---|
| committer | Devon Bleibtrey | 2015-03-23 10:42:42 -0400 | 
| commit | 7ac3c3fff7ae029a331ae0b6c149ac5ab97357fc (patch) | |
| tree | 7a833a0b01191fd3540d2e743a653e7a8a8ad545 /rest_framework | |
| parent | 8a58b1a380cb3544d904524e0f040dca44f972de (diff) | |
| download | django-rest-framework-7ac3c3fff7ae029a331ae0b6c149ac5ab97357fc.tar.bz2 | |
Added enhancement for pk reference in many=True relations
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/relations.py | 3 | 
1 files changed, 2 insertions, 1 deletions
| diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 13668975..7483a939 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -341,6 +341,7 @@ class ManyRelatedField(Field):          assert child_relation is not None, '`child_relation` is a required argument.'          super(ManyRelatedField, self).__init__(*args, **kwargs)          self.child_relation.bind(field_name='', parent=self) +        self.id_field = kwargs.pop('id_field', 'pk')      def get_value(self, dictionary):          # We override the default field access in order to support @@ -362,7 +363,7 @@ class ManyRelatedField(Field):      def get_attribute(self, instance):          # Can't have any relationships if not created -        if not instance.pk: +        if getattr(instance, self.id_field) is None:              return []          relationship = get_attribute(instance, self.source_attrs) | 
