Can someone give a solid example of the deconstruct() mentioned in https://docs.djangoproject.com/en/1.8/topics/migrations/#migration-serializing. I read the doc, and can't really understand with an example.
Asked
Active
Viewed 548 times
1 Answers
0
There is a related Django Ticket - https://code.djangoproject.com/ticket/22951 and here is an example:
class Klass:
def __init__(self, x, y, sep=','):
self.x = x
self.y = y
self.sep = sep
def __str__(self):
return self.sep.join((str(self.x), str(self.y)))
def deconstruct(self):
return 'python.path.to.your.Klass', [self.x, self.y], \
{'sep': self.sep}
And of course don't forget that the order of the returned list of args
should be the same the original order (from the __init__
method) of positional arguments.

Eugene Viktorov
- 1
- 1
-
I had the same question, but this answer just raises more questions. Your __init__ takes four arguments, your deconstruct returns three. – Mike 'Pomax' Kamermans Apr 09 '18 at 17:39