DjangoWiz is a simple and powerful toolkit to automate the generation of serializers, viewsets, URLs, and Docker configurations for your Django projects. This toolkit helps you quickly scaffold out necessary files based on your models, saving you time and effort.
- Automatically generates serializers, viewsets, and URLs based on your Django models.
- Supports generation of Dockerfile and Docker Compose configurations for development and production environments.
- Skips non-serializable classes and abstract models.
- Includes customizable templates using Jinja2.
- Provides flexible commands to generate different components individually or all together.
- Supports custom templates and single file mode.
- Can be used in other Python scripts.
-
Install via pip:
pip install DjangoWiz
-
Alternatively, clone the repository:
git clone https://github.com/tavallie/DjangoWiz.git cd DjangoWiz
-
Install dependencies: Ensure you have Python and Poetry installed, then run:
poetry install
Generate serializers, viewsets, routes, URLs, Dockerfile, and Docker Compose configurations:
djangowiz generate_files <your_app> <your_project> <path/to/models.py> --overwrite
Generate serializers, viewsets, and routes without Docker-related files:
djangowiz generate_core_files <your_app> <your_project> <path/to/models.py> --overwrite
djangowiz generate_serializers <your_app> <your_project> <path/to/models.py> --overwrite
djangowiz generate_viewsets <your_app> <your_project> <path/to/models.py> --overwrite
djangowiz generate_urls <your_app> <your_project> <path/to/models.py> --overwrite
djangowiz generate_routes <your_app> <your_project> <path/to/models.py> --overwrite
You can specify a custom template directory with the --template-dir
option. If a custom template is not provided, the default templates will be used.
djangowiz generate_files <your_app> <your_project> <path/to/models.py> --overwrite --template-dir path/to/custom_templates
You can generate all serializers and viewsets in a single file using the --single-file
option.
djangowiz generate_files <your_app> <your_project> <path/to/models.py> --overwrite --single-file
You can use DjangoWiz in your own Python scripts:
from djangowiz.core import ModelExtractor, ProjectGenerator
model_file = 'path/to/models.py'
model_names = ModelExtractor.extract_model_names(model_file)
generator = ProjectGenerator('your_app', 'your_project', model_names, template_dir='path/to/custom_templates')
generator.generate_all(single_file=True, overwrite=True)
Ensure your project directory is structured as follows:
DjangoWiz/
├── djangowiz/
│ ├── __init__.py
│ ├── core.py
│ ├── cli.py
│ ├── templates/
│ ├── docker-compose.dev.yml.j2
│ ├── docker-compose.prod.yml.j2
│ ├── Dockerfile.j2
│ ├── env.dev.j2
│ ├── env.prod.j2
│ ├── serializer.py.j2
│ ├── viewset.py.j2
│ ├── urls.py.j2
│ ├── routes.py.j2
├── pyproject.toml
├── README.md
├── LICENSE
The templates used for generating files are located in the djangowiz/templates
directory. You can customize these templates to fit your project's specific requirements. The templates use Jinja2 for rendering.
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
Ali Tavallaie - [email protected]
Happy coding!