1. Luke Plant
  2. south


Andrew Godwin  committed 0d545f2

Don't freeze those dastardly dynamic defaults.

  • Participants
  • Parent commits 85b4a6a
  • Branches default

Comments (0)

Files changed (2)

File docs/customfields.rst

View file
  - ignore_if: Specifies an attribute that, if it coerces to true, causes this
    keyword to be omitted. Useful for ``db_index``, which has
    ``{'ignore_if': 'primary_key'}``, since it's always True in that case.
+ - ignore_dynamics: If this is True, any value that is "dynamic" - such as model
+   instances - will cause the field to be omitted instead. Used internally
+   for the ``default`` keyword.
  - is_value: If present, the 'attribute name' is instead used directly as the
    value. See :ref:`above <is-value-keyword>` for more info.

File south/modelsinspector.py

View file
             "max_length": ["max_length", {"default": None}],
             "unique": ["_unique", {"default": False}],
             "db_index": ["db_index", {"default": False}],
-            "default": ["default", {"default": NOT_PROVIDED}],
+            "default": ["default", {"default": NOT_PROVIDED, "ignore_dynamics": True}],
             "db_column": ["db_column", {"default": None}],
             "db_tablespace": ["db_tablespace", {"default": settings.DEFAULT_INDEX_TABLESPACE}],
         return "orm['%s.%s']" % (value._meta.app_label, value._meta.object_name)
     # As do model instances
     if isinstance(value, Model):
+        if options.get("ignore_dynamics", False):
+            raise IsDefault
         return "orm['%s.%s'].objects.get(pk=%r)" % (value.__class__._meta.app_label, value.__class__._meta.object_name, value.pk)
     # Make sure Decimal is converted down into a string
     if isinstance(value, decimal.Decimal):