1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Improve docs around deconstruction/serialisation (refs #22337)

This commit is contained in:
Andrew Godwin
2014-05-06 23:06:41 -07:00
parent f9d7e18dc5
commit 827d5dc189
3 changed files with 44 additions and 0 deletions

View File

@@ -520,6 +520,22 @@ available at the top level of a module it is not serializable.
Django will write out the value as an instantiation of your class with the
given arguments, similar to the way it writes out references to Django fields.
As long as all of the arguments to your class' constructor are themselves
serializable, you can just use the ``@deconstructible`` class decorator
from ``django.utils.deconstruct`` to add the method::
from django.utils.deconstruct import deconstructible
@deconstructible
class MyCustomClass(object):
def __init__(self, foo=1):
...
The decorator adds logic to capture and preserve the arguments on their
way into your constructor, and then returns those arguments exactly when
deconstruct() is called.
Upgrading from South
--------------------