Refactoring a Django App as a Stand-Alone Module
Overview
This page catalogs the workflow involved in taking an app that is part of a Django project and refactoring it as a stand-alone module.
Reusable Django Packages/Apps contains an overview of the principles of creating stand-alone Django modules
Workflow
- project_root_dir
|-- app_dir
| |-- tests/
| |-- __init__.py
| |-- admin.py
| |-- app.py
| `-- models.py
|-- .gitignore
|-- LICENSE
|-- MANIFEST.IN
|-- README.md
`-- setup.py
- Move project files to directory outside Django project, e.g.
~/develop/django/apps - Add package config files
LICENSEMANIFEST.inREADME.mdsetup.py
- Delete
migrationsdirectory - Add project properties in the app directory
__init__.py__author____version__default_app_config = 'app_name.apps.AppNameConfig'
apps.pydefines a class namedAppNameConfigwith the following properties:name- app token, e.g. the name of the directory containing the appverbose_name- Plain english description of the app
- Consider moving views defined in the app out of the app and into the actual Django web applications that references the app.
- N.B. that the Grappelli admin app does not handle models that are broken out into separate files.
UpdateMANIFEST.into include any files that are not in the top level of the app directory.UpdateREADME.mdwith information about installing, configuring, and using the app.Updatesetup.pywith configuration for creating distribution files out of the app.Exclude Mac OS files. PyCharm project files, and distribution files in.gitignore`,