You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing my first Wagtail site in ernest, so, of course, there are some struggles. Some due to my lack of understanding, some due to the docs.
One of these problems is that I'm not sure how to properly add Pages programatically to the site.
The docs are not very helpful. Although they contain lots of good information, it can be hard to find. The search function is not great. Important methods like .add_child are not covered at all (deferred to treebeard docs). The ParentalKey stuff is hardly documented.
I understood there was an initiative to improve the docs. Looking forward to them.
Anyway, enough complaining. Good docs are really hard.
I'd appreciate if someone could take a look at this code. Is that the right Wagtail way?
This code is part of an import management command.
parent_page = InstrumentIndexPage.objects.first()
for item in imported_data:
d=item['fields']
p = InstrumentPage(
title=d['title'],
kind=d['kind'],
phase=d['phase'],
goal=d['goal'],
indications=d['indications'],
contra_indications=d['contra_indications'],
materials=d['materials'],
conditions=d['conditions'],
)
child = parent_page.add_child(instance=p)
mapping[d['pk']]=child.pk
parent_page.save_revision().publish()
In short, this code seems to work, but I'm not sure what I am actually doing.
Questions:
A normal Django object uses save(), which is not adequate for a Wagtail page. Is parent_object.add_child() the nearest equivalent?
Is it necessary to do the save_revision on the parent page?
What if I don't add the publish()? (I have done that of course and I got errors in my template with the routablepageurl template tag)
Thanks for helping me to form a mental model of the Wagtail universe!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm developing my first Wagtail site in ernest, so, of course, there are some struggles. Some due to my lack of understanding, some due to the docs.
One of these problems is that I'm not sure how to properly add Pages programatically to the site.
The docs are not very helpful. Although they contain lots of good information, it can be hard to find. The search function is not great. Important methods like .add_child are not covered at all (deferred to treebeard docs). The ParentalKey stuff is hardly documented.
I understood there was an initiative to improve the docs. Looking forward to them.
Anyway, enough complaining. Good docs are really hard.
I'd appreciate if someone could take a look at this code. Is that the right Wagtail way?
This code is part of an import management command.
In short, this code seems to work, but I'm not sure what I am actually doing.
Questions:
Thanks for helping me to form a mental model of the Wagtail universe!
Beta Was this translation helpful? Give feedback.
All reactions