Reputation: 416
Is there any way I mimic the Wagtail behaviour of creating pages?
The only way that I can think of is to totally replicate the POST
request sent by them upon clicking 'Publish' in the admin interface, but that would be just hideous.
I need this because I need to get a product list from an api, treat them and insert them in my DB. I would prefer to do this through wagtail so I do not drift away from my CMS
In a perfect world this would be a call to some api endpoint where I provide the needed fields in the body of the request.
Upvotes: 1
Views: 576
Reputation: 3977
You can use management command (or any other trigger) to do something like:
from wagtail.core.models import Page
from myapp.models import CustomPage
parent_page = Page.objects.filter(slug="parent_page")[0] # get a suitable parent
page = CustomPage(
title="Sample name",
depth=4,
path="Some random path",
)
parent_page.add_child(instance=page)
Upvotes: 1
Reputation: 11
Why not create a management command.
https://docs.djangoproject.com/en/3.1/howto/custom-management-commands/
Upvotes: 1