From 978aae4334fa71ba78a3e94408f0f3aebde8d07c Mon Sep 17 00:00:00 2001 From: Bendeguz Csirmaz Date: Sun, 7 Apr 2024 10:32:16 +0800 Subject: Fixed #373 -- Added CompositePrimaryKey. Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette Co-authored-by: Lily Foote --- django/core/serializers/python.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'django/core/serializers/python.py') diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 46ef9f0771..57edebbb70 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -7,6 +7,7 @@ other serializers. from django.apps import apps from django.core.serializers import base from django.db import DEFAULT_DB_ALIAS, models +from django.db.models import CompositePrimaryKey from django.utils.encoding import is_protected_type @@ -39,6 +40,8 @@ class Serializer(base.Serializer): return data def _value_from_field(self, obj, field): + if isinstance(field, CompositePrimaryKey): + return [self._value_from_field(obj, f) for f in field] value = field.value_from_object(obj) # Protected types (i.e., primitives like None, numbers, dates, # and Decimals) are passed through as is. All other values are -- cgit v1.3