Skip to content

Generate Django apps and models effortlessly from YAML configuration files. Define your database schema declaratively and automate project setup.

License

Notifications You must be signed in to change notification settings

joegsuero/django-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Django Generator

This package allows you to automatically generate Django applications and models from a YAML configuration file, streamlining your development process by defining your data structure declaratively.

Installation

To install the generator in your development environment, clone this repository and then run the following command from the project root (where setup.py is located):

pip install -e .

This installs the package in editable mode, meaning any changes you make to the source code will be reflected immediately without needing to reinstall.


Usage

  1. Create your YAML configuration file: Define the structure of your Django apps and models in a YAML file. For example, you might name it definition.yaml. Here's a basic example of what it could look like:

    # definition.yaml
    apps:
      - name: products
        models:
          - name: Category
            fields:
              - name: name
                type: CharField
                max_length: 100
          - name: Product
            fields:
              - name: name
                type: CharField
                max_length: 200
              - name: category
                type: ForeignKey
                to: Category
                on_delete: CASCADE
  2. Run the generation command: From the root of your Django project (where you want the new apps to be created, or where your manage.py file is), run the django-gen command, specifying the path to your YAML configuration file and the output directory.

    django-gen --config example/definition.yaml --output example/apps
    • --config example/definition.yaml: Specifies the path to your YAML file.
    • --output backend: Indicates the directory where the Django applications will be generated (in this case, inside a backend/ folder in your current project).

For a more complex YAML file example, look at example/definition.yaml.


Next Steps

Once the generator has finished, don't forget these crucial steps in your Django project:

  1. Register your new apps in the INSTALLED_APPS setting in your settings.py file.
  2. Run python manage.py makemigrations to create the migrations for your new models.
  3. Run python manage.py migrate to apply the changes to your database.

About

Generate Django apps and models effortlessly from YAML configuration files. Define your database schema declaratively and automate project setup.

Topics

Resources

License

Stars

Watchers

Forks