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.
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.
-
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
-
Run the generation command: From the root of your Django project (where you want the new apps to be created, or where your
manage.pyfile is), run thedjango-gencommand, 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 abackend/folder in your current project).
For a more complex YAML file example, look at example/definition.yaml.
Once the generator has finished, don't forget these crucial steps in your Django project:
- Register your new apps in the
INSTALLED_APPSsetting in yoursettings.pyfile. - Run
python manage.py makemigrationsto create the migrations for your new models. - Run
python manage.py migrateto apply the changes to your database.