django_make_app

Define models and fields using YAML and generate app for Django with views, forms, templates etc.


License
MIT
Install
pip install django_make_app==0.1.2

Documentation

Django Make App: generate Django app from YAML

PyPi MIT TravisCI Coverage Requirements Status

Introduction

Django-make-app will generate code of your Django app from a simple YAML schema. This is similar to manage.py startapp but much powerful.

This will be generated from models definitions:

  • Admin classes and admin forms
  • Django REST framework View Sets, Serializers and Router configuration
  • Django AppConfig
  • Django System Checks
  • Forms classes
  • Models classes
  • Detail/Delete/Update/Create/List views, urls and templates
  • Management command example
  • Dummy filter
  • Signals and receivers files
  • TODO tests

Installation

Supported Python versions are: 2.7, 3.4, 3.5, 3.6, pypy and pypy3.

pip install --upgrade django-make-app

Python 3.3 is not supported due to incompatibility of yapf (see: https://github.com/google/yapf#python-versions). If you're on Python 3.3, you can use this package with option django-make-app generate ... --no-optimize (this will skip yapf).

Usage

If you want to generate app called library, create a file app_schema.yaml in project's root and define models:

apps:
    -
        name: library           # all files will be generated into library/ directory (will be created)
        models:
          - User:               # model name
            - name:char         # model field "name" of type "char"
            - email:char        # model field "email" of type "char"
          - Book:               # another model
            - library:fk        # model field "library" of type "foreign key" to "library"
          - Article             # empty model without fields
    -
        name: my_another_awesome_app
        models:
            - City
            - Country

You can also print example configuration by executing (or check templates/example.yaml):

django-make-app write_config > app_schema.yaml

Finally to generate source code of your app, execute:

django-make-app generate library

This structure will be generated:

LIBRARY
|   admin.py
|   api.py
|   apps.py
|   checks.py
|   forms.py
|   models.py
|   receivers.py
|   serializers.py
|   signals.py
|   urls.py
|   views.py
|   __init__.py
|
|---management
|   |   __init__.py
|   |
|   \---commands
|           library_command.py
|           __init__.py
|
|---migrations
|       __init__.py
|
|---templates
|   \---web
|           book_delete.html
|           book_detail.html
|           book_form.html
|           book_list.html
|           article_delete.html
|           article_detail.html
|           article_form.html
|           article_list.html
|           user_delete.html
|           user_detail.html
|           user_form.html
|           user_list.html
|
|---templatetags
|       web_tags.py
|       __init__.py
|
\---tests
        factories.py
        test_book.py
        test_article.py
        test_user.py
        __init__.py

Inspiration

License

The MIT License (MIT)

Copyright (c) 2016–2017 Vašek Dohnal

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.