Fixed #24607 -- Serialized natural keys in multi-table inheritance models.

This commit is contained in:
João Sampaio 2016-10-08 15:09:49 -03:00 committed by Tim Graham
parent 794f866cec
commit 74a575eb72
5 changed files with 68 additions and 3 deletions

View file

@ -13,6 +13,7 @@ from django.db import connections
from django.db.models import Manager
from django.db.models.fields import AutoField
from django.db.models.fields.proxy import OrderWrt
from django.db.models.fields.related import OneToOneField
from django.utils import six
from django.utils.datastructures import ImmutableList, OrderedSet
from django.utils.deprecation import (
@ -296,7 +297,11 @@ class Options(object):
def setup_pk(self, field):
if not self.pk and field.primary_key:
self.pk = field
field.serialize = False
# If the field is a OneToOneField and it's been marked as PK, then
# this is a multi-table inheritance PK. It needs to be serialized
# to relate the subclass instance to the superclass instance.
if not isinstance(field, OneToOneField):
field.serialize = False
def setup_proxy(self, target):
"""