Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nekmo/django-code-generator
Generate code from your Django models for faster development
https://github.com/nekmo/django-code-generator
code-generation code-generator django django-admin django-rest-framework
Last synced: 3 months ago
JSON representation
Generate code from your Django models for faster development
- Host: GitHub
- URL: https://github.com/nekmo/django-code-generator
- Owner: Nekmo
- License: mit
- Created: 2019-05-22T21:36:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-17T06:51:34.000Z (11 months ago)
- Last Synced: 2024-04-24T18:54:03.953Z (9 months ago)
- Topics: code-generation, code-generator, django, django-admin, django-rest-framework
- Language: Python
- Size: 69.3 KB
- Stars: 43
- Watchers: 4
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
#####################
django-code-generator
#####################.. image:: https://img.shields.io/github/workflow/status/Nekmo/django-code-generator/Publish.svg?style=flat-square&maxAge=2592000
:target: https://github.com/Nekmo/django-code-generator/actions?query=workflow%3APublish
:alt: Latest Publish CI build status.. image:: https://img.shields.io/pypi/v/django-code-generator.svg?style=flat-square
:target: https://pypi.org/project/django-code-generator/
:alt: Latest PyPI version.. image:: https://img.shields.io/pypi/pyversions/django-code-generator.svg?style=flat-square
:target: https://pypi.org/project/django-code-generator/
:alt: Python versions.. image:: https://img.shields.io/codeclimate/maintainability/Nekmo/django-code-generator.svg?style=flat-square
:target: https://codeclimate.com/github/Nekmo/django-code-generator
:alt: Code Climate.. image:: https://img.shields.io/codecov/c/github/Nekmo/django-code-generator/master.svg?style=flat-square
:target: https://codecov.io/github/Nekmo/django-code-generator
:alt: Test coverage.. image:: https://img.shields.io/requires/github/Nekmo/django-code-generator.svg?style=flat-square
:target: https://requires.io/github/Nekmo/django-code-generator/requirements/?branch=master
:alt: Requirements StatusGenerate 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:
.. code-block:: console
$ 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.
`More info in the documentation `_Then add it to your ``INSTALLED_APPS``:
.. code-block:: python
INSTALLED_APPS = [
# ...
'django_code_generator',
]Usage
=====
Generating code is as easy as::$ python manage.py generator
This project includes two default templates: ``admin`` and ``api``. For example::
$ python manage.py generator admin myapp
`Read the documentation `_ for more info.
Create templates
================
A template is a directory with files that will be copied to the final path in your app.
Template files can use `Django Templates Syntax `_. When
templates are generated, the app models are available to be used with the django template syntax.For example if you create the template *mytemplate* you can use it for your app *myapp* with the command::
$ python manage.py generate mytemplate myapp
A template file example:
.. code-block:: django
{% load code_generator_tags %}from django.contrib import admin
{% from_module_import app.name|add:'.models' models %}{% comment %}
{% endcomment %}
{% for model in models %}@admin.register({{ model.name }})
class {{ model.name }}Admin(admin.ModelAdmin):
"""
"""
list_display = (
{% indent_items model.filter_field_names 8 quote='simple' %}
)
search_fields = (
{% indent_items model.char_field_names 8 quote='simple' %}
)
{% if model.foreign_field_names %}autocomplete_fields = (
{% indent_items model.foreign_field_names 8 quote='simple' %}
){% endif %}{% endfor %}For more information see `the docs `_.