Skip to main content

Generate code from Django models for faster development

Project description

Latest Travis CI build status Latest PyPI version Python versions Code Climate Test coverage Requirements Status

Generate code from Django models for faster development. This project can generate a Django Rest Framework API or an admin for your app. You can also create your own templates so you can generate code for whatever you want.

To install django-code-generator, run this command in your terminal:

$ sudo pip install django-code-generator

This is the preferred method to install django-code-generator, as it will always install the most recent stable release.

Then add it to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'django_code_generator',
]

Usage

Generating code is as easy as:

$ python manage.py generator <template> <project app>

This project includes two default templates: admin and api. For example:

$ python manage.py generator admin myapp

Create templates

There are several places to locate the directories of your templates. The templates will be loaded in this order:

  1. Template directories in DJANGO_CODE_GENERATOR_TEMPLATES environment variable. The directories are separated by a colon char (:). For example: DJANGO_CODE_GENERATOR_TEMPLATES=/path/templates/.

  2. Templates from the folder .dcg_templates/ in the current directory.

  3. Template directories from DJANGO_CODE_GENERATOR_TEMPLATES = [] list in your Django settings.

  4. Templates from folder .dcg_templates/ in manage.py directory.

  5. Templates from ~/.config/dcg_templates/ directory.

  6. Templates from django_code_generator project

To create the template, make a directory with the name of the template in the templates folder. For example: ~/.config/dcg_templates/mytemplate/. When you use the command manage.py generate <template> <project app> everything inside the template folder will be copied and rendered to the app folder in your Django project.

For example, running manage.py generate mytemplate myapp the file ~/.config/dcg_templates/mytemplate/admin.py will be copied and rendered to myproject/myapp/admin.py.

Django Code Generate uses Django Templates Syntax for to render the templates. You can find examples in this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-code-generator-0.2.1.tar.gz (18.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page