Normalise the output of StreamField.deconstruct to a list of block defs.

This ensures that the migration code is the same even if the StreamBlock is defined as an external instance or class, and that in those cases the block definitions get frozen into the migration.
This commit is contained in:
Matt Westcott 2015-02-13 21:37:37 +00:00
parent 0ee9649415
commit 17acb8867d

View file

@ -42,8 +42,6 @@ class RichTextField(models.TextField):
class StreamField(with_metaclass(models.SubfieldBase, models.Field)):
def __init__(self, block_types, **kwargs):
self.block_types = block_types
if isinstance(block_types, Block):
self.stream_block = block_types
elif isinstance(block_types, type):
@ -56,8 +54,9 @@ class StreamField(with_metaclass(models.SubfieldBase, models.Field)):
return 'TextField'
def deconstruct(self):
name, path, args, kwargs = super(StreamField, self).deconstruct()
kwargs['block_types'] = self.block_types
name, path, _, kwargs = super(StreamField, self).deconstruct()
block_types = self.stream_block.child_blocks.items()
args = [block_types]
return name, path, args, kwargs
def to_python(self, value):