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:

    # ...


Generating code is as easy as:

$ python generator <template> <project app>

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

$ python 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 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 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 generate mytemplate myapp the file ~/.config/dcg_templates/mytemplate/ will be copied and rendered to myproject/myapp/

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.

Files for django-code-generator, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size django-code-generator-0.2.1.tar.gz (18.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page