0

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.

user1187968
  • 7,154
  • 16
  • 81
  • 152

1 Answers1

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.