Generate code from Django models for faster development
Project description
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:
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/.
Templates from the folder .dcg_templates/ in the current directory.
Template directories from DJANGO_CODE_GENERATOR_TEMPLATES = [] list in your Django settings.
Templates from folder .dcg_templates/ in manage.py directory.
Templates from ~/.config/dcg_templates/ directory.
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
File details
Details for the file django-code-generator-0.2.0.tar.gz
.
File metadata
- Download URL: django-code-generator-0.2.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32f6d9ce2dd7fd8156f9877d202eb87fda94afcdce954e0d17c8126f91674d99 |
|
MD5 | c44dfd0c57d41bdcc57cc98adb4cb15e |
|
BLAKE2b-256 | 82d63fa954920b96dea0f0773a9027a87061df9db2e99a0f7ddd31bfd72438ab |