Skip to main content

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:

  1. Creates appropriate directories (models/, views/, serializers/, etc.)
  2. Extracts classes from single files into individual modules
  3. Updates import statements automatically
  4. Creates __init__.py files with correct imports
  5. 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__.py files
  • 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

  1. Use Descriptive Names: Name your elements clearly (e.g., UserProfileSerializer instead of just Serializer)
  2. Organize Related Components: Use the --path option to group related components
  3. Folderize Early: Convert to directory structure early in development
  4. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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:

  1. Check the existing issues on GitHub
  2. Create a new issue if needed
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_create-0.1.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_create-0.1.3-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file django_create-0.1.3.tar.gz.

File metadata

  • Download URL: django_create-0.1.3.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.0 Windows/10

File hashes

Hashes for django_create-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0dc368bb8532f72f29d7fd3c957514d65ae16b3b7b9c514da8e0b84b9a6cdef0
MD5 7ccc56ed5dae49e7346797a6fdf7170f
BLAKE2b-256 bf43db544bdbcafea7182eb4308a0511f0bd86e576671c93b8497264def3c23a

See more details on using hashes here.

File details

Details for the file django_create-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_create-0.1.3-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

Hashes for django_create-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2ea9cc88832a70b9a4aee97c9375e3536a12b4aa3e481250680e9282ae627e4
MD5 3cc638e12c9abac8386176accc31f3c1
BLAKE2b-256 d0ca39264af426b53f568592ae4d0325106fa83b647d713e2e36f93039a38ae7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page