mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Merge ecf8c6f6ff
into 6d4d4dfd04
This commit is contained in:
commit
dba07b4da0
|
@ -501,11 +501,20 @@ class ManyRelatedField(Field):
|
|||
if not self.allow_empty and len(data) == 0:
|
||||
self.fail('empty')
|
||||
|
||||
return [
|
||||
if isinstance(self.child_relation, PrimaryKeyRelatedField):
|
||||
values = list(self.child_relation.get_queryset().filter(pk__in=data))
|
||||
missing_primary_keys = set(v.pk for v in values) - set(data)
|
||||
|
||||
if missing_primary_keys:
|
||||
self.fail('missing_ids', ids_not_found=list(missing_primary_keys))
|
||||
else:
|
||||
values = [
|
||||
self.child_relation.to_internal_value(item)
|
||||
for item in data
|
||||
]
|
||||
|
||||
return values
|
||||
|
||||
def get_attribute(self, instance):
|
||||
# Can't have any relationships if not created
|
||||
if hasattr(instance, 'pk') and instance.pk is None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user