Finish the Django configuration

by John Samuel Anderson last modified Jul 02, 2010 01:55 PM
Show ATContentTypes in Django.

New Django App for Archetypes Content

  1. Create a new "app" to hold your Archetypes Content
    python manage.py startapp atcontent
  2. Let Django make basic models out of ContentMirror tables
    python manage.py inspectdb > atcontent/models.py
  3. Edit the generated code, per the comments django puts in it. (Django will warn you on the next step if you get it wrong.)
    • Remove django default table definitions.
    • Removed auto-generated "id" fields, because Django infers them anyway and complains if you define them yourself.
    • Reorder the model classes so that references come after the model classes they refer to are defined.
    • Add related_name parameters to ForeignKey definitions where necessary.
    • The second time I did this, I also removed "At" from the Django model class names; since the Django app is "atcontent," it just seemed redundant.
  4. Make sure that your data model is valid. (If it's not, go back to the previous step and fix it.)
    python manage.py sql atcontent
  5. Synchronize with the db.
    python manage.py syncdb

 

Here's the file I came up with (use at your own risk): models.py

Plug in the App and start serving

  1. Add "atcontent" to INSTALLED_APPS in mydjangoproject/settings.py.
  2. Add a custom admin.py in your app.  (Here's the file I used: admin.py). If you're brave, you can add some neat filtering and searching to the admin interface, using Django ModelAdmin classes.
  3. Add the admin panel and follow the other instructions in this tutorial:

http://docs.djangoproject.com/en/dev/intro/tutorial02/#intro-tutorial02

 At this point, all of the default Plone Content Types are now mirrored to Django. You can (sort-of) view them via the admin interface. However, they're not pretty. (If you want that, you'll need to build Django "views". This document is not going to cover that. Sorry.)

Here's what it looks like:

Django admin interface to ATContentTypes