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.0.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file django-code-generator-0.2.0.tar.gz.

File metadata

File hashes

Hashes for django-code-generator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 32f6d9ce2dd7fd8156f9877d202eb87fda94afcdce954e0d17c8126f91674d99
MD5 c44dfd0c57d41bdcc57cc98adb4cb15e
BLAKE2b-256 82d63fa954920b96dea0f0773a9027a87061df9db2e99a0f7ddd31bfd72438ab

See more details on using hashes here.

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