From 9225f0814118c17af857c85a7cc5319bbb48ee43 Mon Sep 17 00:00:00 2001 From: Michael Scott Cuthbert Date: Mon, 29 Jan 2018 20:04:41 -0500 Subject: [PATCH] Give an example of copying a polymorphic object --- docs/advanced.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/advanced.rst b/docs/advanced.rst index bcffe50..a091c8e 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -92,6 +92,20 @@ A ManyToManyField example:: , ] +Copying Polymorphic objects +--------------------------- + +When creating a copy of a polymorphic object, both the +``.id`` and the ``.pk`` of the object need to be set +to ``None`` before saving so that both the base table +and the derived table will be updated to the new object:: + + >>> o = ModelB.objects.first() + >>> o.field1 = 'new val' # leave field2 unchanged + >>> o.pk = None + >>> o.id = None + >>> o.save() + Using Third Party Models (without modifying them) -------------------------------------------------