Git Product home page Git Product logo

django-code-generator's Introduction

django-code-generator

Latest Publish 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. More info in the documentation

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

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:

{% 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.