diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2014-09-24 19:07:56 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-09-24 14:19:11 -0400 |
| commit | 066e672d79ceb416ac87e51c8fa400221fa8604f (patch) | |
| tree | 14ad2983b2598800d89eeffbbdbb3dc072bf106f /docs | |
| parent | 450a61600407d7320b85b75b441ce67b199da68b (diff) | |
Fixed #23473 -- Documented that @deconstructible classes need __eq__.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/migrations.txt | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt index a188ea10c2..90e1a728a2 100644 --- a/docs/topics/migrations.txt +++ b/docs/topics/migrations.txt @@ -601,9 +601,14 @@ of three things ``(path, args, kwargs)``: 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. +To prevent a new migration from being created each time +:djadmin:`makemigrations` is run, you should also add a ``__eq__()`` method to +the decorated class. This function will be called by Django's migration +framework to detect changes between states. + 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:: +serializable, you can use the ``@deconstructible`` class decorator from +``django.utils.deconstruct`` to add the ``deconstruct()`` method:: from django.utils.deconstruct import deconstructible @@ -611,8 +616,13 @@ from ``django.utils.deconstruct`` to add the method:: class MyCustomClass(object): def __init__(self, foo=1): + self.foo = foo ... + def __eq__(self, other): + return self.foo == other.foo + + 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. |
