Open ababic opened 3 years ago
The implementation above could easily be built upon to:
create()
is called)default_factory_class
and data source for the management command (specified via dotted python path strings)Intriguing idea, but I'm not clear what would need to be built into wagtail-factories
to support this use case. At first glance, a lot of your example looks like it'd be very specific to a particular project and there isn't a lot of code around just invoking the project's own factory classes.
Could you be more specific or maybe raise a PR?
I think part of the issue is the sparse documentation around calling the factories (especially streamfield ones) in ways that will work. Like linking to something like body__0__carousel__items__0__label='Slide 1',
in tests doesn't make a ton of sense by itself.
@bcdickinson thanks for getting back to me. The idea here is that the CreatePageNode
is generic enough to be used to create any number of pages, in any structure, and of any type. So perhaps that could find a home within the project as a util
of sorts, with the other code examples possibly being translated into documentation on how to use it?
Or maybe the entire thing would go into the docs, as hinted at by @easherma-truth?
Or, if you don't see a place for this sort of thing in the project at all, that's equally fine. I just thought it would be helpful for others.
For a lot of projects, it can be helpful to establish the general 'page structure' of a site early on.
In the past, I've used
fixtures
for this, but I find them cumbersome. Every time you decide to switch up your model classes or fields, the fixtures remain unaware and require either a painful 'manual update' process, or a painful 'manually populate the tree locally and re-dump everything' process.In a recent project, I decided that, since we were mostly defining a factory for every page type, we could use factories instead! I came up with the following:
This can then be used to define a 'page tree to create', like so:
This can easily be incorporated into a management command that can trigger creation of all of these pages, like so:
The process safely avoids creating/overwriting pages that already exist - meaning it can be rerun at a later time to add new sections (as the page types are developed)