summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-05-19 12:35:17 +0200
committerAndrew Godwin <andrew@aeracode.org>2013-05-19 12:35:17 +0200
commit264f8650e375112e874298ec1c5ba65b193fda2a (patch)
tree85ffce9ce472ca513139dc7f9261f83a9a1efefc /django/db
parentd58c98d73c41b97e9543f88d3a81ffa6f23e4c7d (diff)
ModelState now freezes options and bases
Diffstat (limited to 'django/db')
-rw-r--r--django/db/migrations/state.py13
-rw-r--r--django/db/models/options.py6
2 files changed, 17 insertions, 2 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index d695b1a0c4..44ee166121 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -1,5 +1,6 @@
from django.db import models
from django.db.models.loading import BaseAppCache
+from django.db.models.options import DEFAULT_NAMES
from django.utils.module_loading import import_by_path
@@ -66,13 +67,21 @@ class ModelState(object):
name, path, args, kwargs = field.deconstruct()
field_class = import_by_path(path)
fields.append((name, field_class(*args, **kwargs)))
+ # Extract the options
+ options = {}
+ for name in DEFAULT_NAMES:
+ # Ignore some special options
+ if name in ["app_cache", "app_label"]:
+ continue
+ if name in model._meta.original_attrs:
+ options[name] = model._meta.original_attrs[name]
# Make our record
return cls(
model._meta.app_label,
model._meta.object_name,
fields,
- {},
- None,
+ options,
+ model.__bases__,
)
def clone(self):
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 46c18a64c6..1a9421c0fa 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -85,6 +85,10 @@ class Options(object):
self.model_name = self.object_name.lower()
self.verbose_name = get_verbose_name(self.object_name)
+ # Store the original user-defined values for each option,
+ # for use when serializing the model definition
+ self.original_attrs = {}
+
# Next, apply any overridden values from 'class Meta'.
if self.meta:
meta_attrs = self.meta.__dict__.copy()
@@ -97,8 +101,10 @@ class Options(object):
for attr_name in DEFAULT_NAMES:
if attr_name in meta_attrs:
setattr(self, attr_name, meta_attrs.pop(attr_name))
+ self.original_attrs[attr_name] = getattr(self, attr_name)
elif hasattr(self.meta, attr_name):
setattr(self, attr_name, getattr(self.meta, attr_name))
+ self.original_attrs[attr_name] = getattr(self, attr_name)
# unique_together can be either a tuple of tuples, or a single
# tuple of two strings. Normalize it to a tuple of tuples, so that