Question

What would be the best way to port an existing Drupal site to a Django application? I have around 500 pages (mostly books module) and around 50 blog posts. I'm not using any 3rd party modules. I would like to keep the current URLS (for SEO purposes) and migrate database to Django. I will create a simple blog application, so migrating blog posts should be ok. What would be the best way to serve 500+ pages with Django? I would like to use Admin to edit/add new pages.

Was it helpful?

Solution

All Django development is similar, and yours will fit the pattern.

  1. Define the Django model for your books and blog posts.

  2. Unit test that model using Django's built-in testing capabilities.

  3. Write some small utilities to load your legacy data into Django. At this point, you'll realize that your Django model isn't perfect. Good. Fix it. Fix the tests. Redo the loads.

  4. Configure the default admin interface to your model. At this point, you'll spend time tweaking the admin interface. You'll realize your data model is wrong. Which is a good thing. Fix your model. Fix your tests. Fix your loads.

  5. Now that your data is correct, you can create templates from your legacy pages.

  6. Create URL mappings and view functions to populate the templates from the data model.

Take the time to get the data model right. It really matters, because everything else is very simple if your data model is solid.

OTHER TIPS

It may be possible to write Django models which work with the legacy database (I've done this in the past; see docs on manage.py inspectdb).

However, I'd follow advice above and design a clean database using Django conventions, and then migrate the data over. I usually write migration scripts which write to the new database through Django and read the old one using the raw Python DB APIs (while it is possible to tie Django to multiple databases simultaneously, too).

I also suggest taking a look at the available blogging apps for Django. If the one included in Pinax suits your need, go ahead and use Pinax as a starting point.

S.Lott answer is still valid after years, I try to complete the analysis with the tools and format to do the job.

There are many Drupal export tools out of there by now but with the very same request I go for Views Datasource choosing JSON as format. This module is very solid and available for the last version of Drupal. The JSON format is very fast in both parsing and encoding and it's easy to read and very Python-friendly (import json).

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

When importing in Django you have a wide set of tools as well, starting from loaddata to load fixtures. Views Datasource exported JSON but it's not formatted as Django expects fixtures: you can write a custom admin command to do the import, where you can have the full control of the import flow.

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

Regarding performance, just for example I parsed and imported 15.000+ nodes in less than 10 minutes via a Django 1.8 custom admin command on an 8 core / 8 GB Linux virtual machine and PostgreSQL as DBMS, logging success and error information into a custom model for each node.

These are the basics for import/export between these two platform, for detailed information I described all the major steps for export from Drupal and then import to Django in this guide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top