How to port from Drupal to Django?

What would be the best way to port an existing Drupal site to a Django application? I have about 500 pages (mostly a book module) and about 50 blog posts. I do not use third-party modules. I would like to keep the current URLs (for SEO purposes) and migrate the database to Django. I will create a simple blog application so blog posting should be fine. What would be the best way to serve more than 500 pages with Django? I would like to use admin to edit / add new pages.

+6
django drupal
source share
3 answers

All Django developments are similar, and yours will follow the pattern.

  • Define a Django model for your books and blog posts.

  • Unit test This model uses the built-in testing capabilities of Django.

  • Write some small utilities to load your legacy data into Django. At this point, you will realize that your Django model is not perfect. Good. Fix it. Correct the tests. Retry the download.

  • Configure the default admin interface for your model. At this point, you will spend time setting up the admin interface. You will understand that your data model is incorrect. What well. Correct your model. Correct your tests. Correct your loads.

  • Now that your data is correct, you can create templates from old pages.

  • Create URL mappings and view functions to populate patterns from the data model.

Take the time to get the data model correctly. This is really important because everything else is very simple if your data model is solid.

+12
source share

Perhaps it is possible to write Django models that work with an outdated database (I did this in the past, see the docs on manage.py inspectdb ).

However, I would advise above and develop a clean database using Django conventions and then migrate the data. I usually write migration scripts that write to the new database via Django and read the old one using the raw Python DB APIs (while you can associate Django with multiple databases at the same time ).

I also suggest taking a look at the affordable blogging apps for Django. If the one that is included in Pinax meets your needs, use Pinax as a starting point.

+3
source share

S.Lott's answer remains valid after several years, I am trying to complete the analysis with the tools and format for the task.

There are many Drupal export tools now, but with the same request I go for Views Datasource , choosing JSON as the format. This module is very robust and available for the latest version of Drupal. The JSON format is very fast for parsing and coding, and it is easy to read and very convenient for Python ( import json ).

Using Views Datasource, you can create a node view sorted by node id (nid), show a limited number of elements on the page, configure the viewing path, add a filter identifier to it and pass it nid to read all the elements until you get an empty JSON response .

When importing into Django, you also have a wide range of tools, starting with loaddata for loading fixtures . Datasource views exported JSON, but it is not formatted, because Django expects a snap-in: you can write a custom admin command for import, where you can get full control of the import stream.

You can run your command by passing nid = 0 as an argument, and then let the procedure read, import, and then retrieve data from the next page, skipping the last last code read in the previous HTTP request. You can even restrict access to the path view, but you need additional configuration on the import side.

As regards performance, for example, I analyzed and imported 15,000+ nodes in less than 10 minutes using the special Django 1.8 admin command on a Linux virtual machine with 8 kernels / 8 GB and PostgreSQL as a DBMS, success logging and error information in custom model for each node.

These are the basics for import / export between the two platforms. For details, I described all the basic steps for exporting from Drupal, and then importing to Django in this guide .

0
source share

All Articles