-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to specify default values for StreamBlockFactory #57
Comments
@bcdickinson I am confused by the |
If the issue we are trying to solve is the fact that the block "descriptor" (not sure what to call it) starts with a number (because we don't know the name of the field on the parent), could we just use something generic as the start for the string like |
In this case, this means that the 0th item in the generated @bcdickinson it might be worth changing To allow specifying Question: given a class BodyFactory(StreamBlockFactory):
struct_1 = SubFactory(Struct1Factory)
struct_2 = SubFactory(Struct2Factory)
class Meta:
default_data = {"0": "struct_1", "1": "struct_1"} and a call like {
"0": "struct_1", # from meta.default_data,
"1": "struct_2", # from extras at page factory instantiation
} ? |
Potentially related: #60 |
I found, you can use factory boy's
|
This is a pre-emptive issue ahead of the merge of #55 to document a missing feature without unnecessarily holding up that PR. The PR adds a new
StreamBlockFactory
class that can be passed as the argument to aStreamFieldFactory
declaration. The missing feature is the ability to specify the default value of aStreamBlockFactory
subclass, either when it's passed toStreamFieldFactory
or on the class definition itself.The relationship between
StreamFieldFactory
andStreamBlockFactory
is a bit like the relationship betweenSubFactory
andFactory
, so it'd be nice to be able to do something similar to the**kwargs
thatSubFactory.__call__
accepts to set the default value of the generated stream data. However, the values will always start with block indexes (e.g.0__my_block_type__some_attribute="foo"
) which aren't legal Python kwarg names, so my proposal for this API would be to accept an optionaldict
-like object that defines the defaults, something like:The above should work well for defining default data for a given use of a
StreamBlockFactory
, it would also be useful to be able to specify default values as part of theStreamBlockFactory
definition as well, so that the same data could be used in multiple places without being redefined. I'm less sure how the API for this should look, but one idea might be adding a newdefault_data
member to theMeta
class, something like this:The text was updated successfully, but these errors were encountered: