1
0
mirror of https://github.com/django/django.git synced 2025-10-27 23:56:08 +00:00

ModelState now freezes options and bases

This commit is contained in:
Andrew Godwin
2013-05-19 12:35:17 +02:00
parent d58c98d73c
commit 264f8650e3
3 changed files with 22 additions and 2 deletions

View File

@@ -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):