Skip to content

Commit

Permalink
Fixed #21010 -- Changed ModelState to only copy _meta.local_fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
loic authored and timgraham committed Sep 4, 2013
1 parent 533d1ab commit 34d52fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/migrations/state.py
Expand Up @@ -70,7 +70,7 @@ def from_model(cls, model):
"""
# Deconstruct the fields
fields = []
for field in model._meta.fields:
for field in model._meta.local_fields:
name, path, args, kwargs = field.deconstruct()
field_class = import_by_path(path)
fields.append((name, field_class(*args, **kwargs)))
Expand Down
19 changes: 19 additions & 0 deletions tests/migrations/test_state.py
Expand Up @@ -75,3 +75,22 @@ def test_render(self):
new_app_cache = project_state.render()
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)

def test_render_multiple_inheritance(self):
# Use a custom app cache to avoid polluting the global one.
new_app_cache = BaseAppCache()

class Book(models.Model):
title = models.CharField(max_length=1000)

class Meta:
app_label = "migrations"
app_cache = new_app_cache

class Novel(Book):
class Meta:
app_label = "migrations"
app_cache = new_app_cache

yet_another_app_cache = BaseAppCache()
ModelState.from_model(Novel).render(yet_another_app_cache)

0 comments on commit 34d52fd

Please sign in to comment.