0

Wagtail and Django are very efficient and sophisticated frameworks, but they do not offer any simple way of importing (i.e bulk creating) pages. I have tried dozens of suggestions to do so (eg 1, eg 2, eg 3, eg 4, etc). I've also tried CodeRedCMS (which is based on Wagtail), but it offers a very rudimentary function and I do not want to add additional dependencies. Gazmans solution in this post seemed very efficient but I could not figure out exactly how to go about solving the issue.

So my question is simple: If I have a csv/json file with thousands of rows, where each row represents a post for a specific Page Model I've created in Wagtail, how do I import it to Wagtail? Any example with psuedo code would be immensely appreciated.

The solutions that I almost succeed with were by (1) either using DataGrip and directly import data into the table, or (2) using the loaddata management command in Django. However, both these methods resulted in Wagtail not registering the entries, such that I could verify that they existed in the database table but not in the parent table and not visible in the admin backend, which I believe is due to multi-table inheritance.

LauperEd
  • 25
  • 3

1 Answers1

2

Here's a recipe which should point you in the right direction:

https://gist.github.com/tomdyson/ef8c2f684620b84feaddfd7454e09647

This shows the creation of an example Film page model for Wagtail, along with a management command which creates ~35k pages from a downloaded CSV file.

You could also check out my wagtail-fakenews app, which generates Wagtail pages with dummy content. It doesn't import from CSV, but it does include images and StreamField content (see make_fake_items.py), which the first recipe doesn't.

tomd
  • 1,373
  • 1
  • 8
  • 12