I'm new to Django and Wagtail and trying to set my CMS up to load with the minimum set of pages for our nav to function correctly. The short problem is that objects extending Wagtail's Page
type are not loading, though the data migration appears to succeed.
In my case I have a bunch of Organization
s & OrganizationType
s (extending BasicObject
), as well as some Page
objects: OrganizationIndexPage
s OrganizationPage
s. I've dumped the data using the standard dumpdata
command and have it, including all pages, in an initial_data.json file and am loading it using a data migration similar to the accepted answer here. The problem is that I get all my Organizations and OrganizationTypes, but no Page objects after re-migrating. I even added some printing to the output to verify:
loaded <DeserializedObject: orgs.Organization(pk=19)>
loaded <DeserializedObject: orgs.Organization(pk=20)>
loaded <DeserializedObject: orgs.OrganizationType(pk=1)>
loaded <DeserializedObject: orgs.OrganizationType(pk=2)>
loaded <DeserializedObject: orgs.OrganizationType(pk=3)>
loaded <DeserializedObject: orgs.OrganizationPage(pk=7)>
loaded <DeserializedObject: orgs.OrganizationPage(pk=8)>
loaded <DeserializedObject: orgs.OrganizationPage(pk=10)>
edit: I've noticed that in my dumped json that some fields that are probably required are missing from my pages. I'm just calling save()
on my deserialized json objects. However, if I drop into the database those missing rows are there- I can't even create a new page for an organization in the wagtail interface dut to a OneToOneField
relationship... but they don't appear in the interface or in the shell using OrganizationPage.objects.all()
(I'm new to everything so maybe not using the shell right either).
Here is an example initial json and its corresponding Page model:
# Example json
{
"model": "orgs.organizationpage",
"pk": 21,
"fields": {
"org": 14,
"body": "[{\"type\": \"paragraph\", \"value\": \"<p>Here is the body</p>\", \"id\": \"804642df-31f8-4e17-b114-cb05c4b3e265\"}]"
}
},
# Page class
class OrganizationPage(Page):
org = models.OneToOneField('orgs.Organization', on_delete=models.PROTECT)
body = StreamField([
('heading', HeadingBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
('table', TableBlock()),
])
api_fields = [
APIField('org'),
APIField('body'),
]
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
search_fields = Page.search_fields + [
SearchField('body'),
]
settings_panels = Page.settings_panels + [
FieldPanel('org'),
]
# load_fixture function from migration
def load_fixture(apps, schema_editor):
fixture_file = os.path.join(fixture_dir, fixture_filename)
fixture = open(fixture_file, 'rb')
objects = serializers.deserialize('json', fixture, ignorenonexistent=True)
for obj in objects:
obj.save()
print("loaded {}".format(obj))
fixture.close()