A CLI tool to help Django developers create file templates.
Project description
Django Create
A powerful CLI tool for organizing and maintaining Django applications with a focus on scalability and code organization.
Overview
Django Create helps you maintain clean and organized Django applications by providing tools to:
- Create and organize Django models, views, serializers, viewsets, and tests
- Convert single-file modules into organized directory structures
- Maintain consistent import statements and file organization
- Support nested directory structures for complex applications
Installation
# Using pip
pip install django-create
# Using Poetry
poetry add django-create
Usage
Basic Commands
The basic structure of commands is:
django-create <app_name> <command> <element_name> [options]
Creating New Elements
Create new Django elements with automatic file organization:
# Create a new model
django-create myapp create model UserProfile
# Create a new view
django-create myapp create view UserListView
# Create a new serializer with associated model
django-create myapp create serializer UserSerializer --model User
# Create a new viewset with model and serializer
django-create myapp create viewset UserViewSet --model User --serializer UserSerializer
# Create a new test
django-create myapp create test UserTest
Organizing Elements in Subdirectories
You can organize elements in subdirectories using the --path option:
# Create a model in a subdirectory
django-create myapp create model ProductVariant --path products/variants
# Create a view in a subdirectory
django-create myapp create view ProductListView --path products/lists
Folderizing an App
The folderize command converts a Django app from single-file modules to an organized directory structure:
django-create myapp folderize
This command:
- Creates appropriate directories (
models/,views/,serializers/, etc.) - Extracts classes from single files into individual modules
- Updates import statements automatically
- Creates
__init__.pyfiles with correct imports - Removes the original single files
For example, models.py containing multiple models would be split into:
models/
├── __init__.py
├── user.py
├── profile.py
└── settings.py
Directory Structure
After using folderize command, your app structure might look like this:
myapp/
├── models/
│ ├── __init__.py
│ ├── user.py
│ └── profile.py
├── views/
│ ├── __init__.py
│ ├── user_views.py
│ └── profile_views.py
├── serializers/
│ ├── __init__.py
│ ├── user_serializer.py
│ └── profile_serializer.py
├── viewsets/
│ ├── __init__.py
│ ├── user_viewset.py
│ └── profile_viewset.py
└── tests/
├── __init__.py
├── test_models.py
└── test_views.py
Features
- Automatic Import Management: Correctly handles relative imports and updates
__init__.pyfiles - Nested Directory Support: Create and maintain complex directory structures
- Template-Based Generation: Consistent file creation using predefined templates
- Smart File Organization: Converts single-file modules into organized directories
- Import Statement Optimization: Merges and organizes import statements efficiently
- Conflict Prevention: Prevents issues with duplicate files/folders
- Clean Migration: Safely moves from single-file to directory structure
Best Practices
- Use Descriptive Names: Name your elements clearly (e.g.,
UserProfileSerializerinstead of justSerializer) - Organize Related Components: Use the
--pathoption to group related components - Folderize Early: Convert to directory structure early in development
- Maintain Structure: Continue using the CLI tools after folderizing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Testing
To run the test suite:
pytest
License
MIT License - see the LICENSE file for details
Support
If you encounter any issues or have questions, please:
- Check the existing issues on GitHub
- Create a new issue if needed
- Provide detailed information about your environment and the problem
Future Plans
- Add support for DRF generic views
- Include customizable templates
- Add support for Django signals
- Implement database migration helpers
- Add support for Django admin customization
Credits
Created and maintained by Jonathan Ribak.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_create-0.1.4.tar.gz.
File metadata
- Download URL: django_create-0.1.4.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b483f9ff6a1daba005b3d9a7c1e07b92264b03b5d2067e6d89cf905b52be6be2
|
|
| MD5 |
25f1ac039425a00bad0328be14407bef
|
|
| BLAKE2b-256 |
efa73a9f846e29ad28613670e18a7df5ef15e77bf7219133ca97ee2790bd9a0b
|
File details
Details for the file django_create-0.1.4-py3-none-any.whl.
File metadata
- Download URL: django_create-0.1.4-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7553690cad4c0f0d6cb04984fbee1a70ba6406dd5e978dbeb373f1655347bf4
|
|
| MD5 |
63b5c4e0fd658ae08c38b79b95d00d73
|
|
| BLAKE2b-256 |
b92057a1f56869fe40a03e17d5854ba9eec9dd91a113a70f415b27e20fa3869c
|