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 have created a Django management command that creates the initial Wagtail site structure. This works reasonably well, but I have encountered a problem: Although the pages are shown as "Live" in the WT UI, they are not really. Pageurls render as None, so links are broken. It can be easily worked around by manually publishing the pages again. Then everything works as normal.
I'd really like to know what I'm doing wrong.
This is the relevant code:
defhandle(self, *args, **options):
site=Site.objects.get(is_default_site=True)
root=Page.get_first_root_node()
old_home=root.get_first_child() # don't throw away yet because this will remove the site as well!new_home=HomePage(title="Testwijzer home")
root.add_child(instance=new_home)
site.root_page=new_homesite.site_name='Testwijzer'site.save()
# now we can remove the old home pageold_home.delete()
# change the home page slug:new_home.slug='home'new_home.save_revision().publish()
self.stdout.write(self.style.SUCCESS('Changed home page successfully.'))
# Check if AspectIndex page exists; if not, create itaspect_index_page=AspectIndexPage.objects.first()
ifnotaspect_index_page:
aspect_index_page=AspectIndexPage(title="Aspect Index",
slug='aspect-index',
body='Overzicht van alle aspecten')
new_home.add_child(instance=aspect_index_page)
self.stdout.write(self.style.SUCCESS('AspectIndexPage page added successfully.'))
else:
self.stdout.write(self.style.WARNING('AspectIndexPage already exists.'))
In this example the Aspect Index Page would exhibit the erroneous behavior.
On the topic of programatically creating objects: AFAICT this is not documented, ssh the code above is what I think is the right way. Especially the relation between Site and Root and pages is somewhat nebulous to me.
If someone could share some example code on the proper way to do this, that would be wonderful.
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
-
Hi all,
I have created a Django management command that creates the initial Wagtail site structure. This works reasonably well, but I have encountered a problem: Although the pages are shown as "Live" in the WT UI, they are not really. Pageurls render as None, so links are broken. It can be easily worked around by manually publishing the pages again. Then everything works as normal.
I'd really like to know what I'm doing wrong.
This is the relevant code:
In this example the Aspect Index Page would exhibit the erroneous behavior.
On the topic of programatically creating objects: AFAICT this is not documented, ssh the code above is what I think is the right way. Especially the relation between Site and Root and pages is somewhat nebulous to me.
If someone could share some example code on the proper way to do this, that would be wonderful.
Beta Was this translation helpful? Give feedback.
All reactions