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.

Link to Github repository

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.4.tar.gz (14.5 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.4-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

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

Hashes for django_create-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b483f9ff6a1daba005b3d9a7c1e07b92264b03b5d2067e6d89cf905b52be6be2
MD5 25f1ac039425a00bad0328be14407bef
BLAKE2b-256 efa73a9f846e29ad28613670e18a7df5ef15e77bf7219133ca97ee2790bd9a0b

See more details on using hashes here.

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

Hashes for django_create-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b7553690cad4c0f0d6cb04984fbee1a70ba6406dd5e978dbeb373f1655347bf4
MD5 63b5c4e0fd658ae08c38b79b95d00d73
BLAKE2b-256 b92057a1f56869fe40a03e17d5854ba9eec9dd91a113a70f415b27e20fa3869c

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