# DJANGO-SWIFT-CRUD Package
## Motiviation
Creating CRUD operations for Django models can often be a tedious, especially when dealing with the complexities of Class-Based Views. With the swift_crud package, we provide a streamlined solution that eliminates the need to navigate through inheritance hierarchies and override methods. Our goal is to empower developers to quickly and efficiently set up CRUD operations for any Django model with just one view class, saving valuable time and ensuring a smoother development process. Let swift_crud simplify your workflow and enhance your productivity.
## Overview
The `swift_crud` package provides a base view class (`SwiftView`) and utility functions to quickly set up CRUD (Create, Read, Update, Delete) operations for any Django model with only one view class. This package aims to simplify the process by abstracting away the complexity of built-in Class-Based Views (CBVs) and the need to track the inheritance hierarchy to determine where to override methods.
The package includes several mixins to handle common tasks, such as:
- Rendering templates
- Managing redirects
- Handling querysets
- Processing forms
By utilizing these mixins, developers can easily implement CRUD functionality for their Django models without having to write boilerplate code or navigate the intricate details of the CBV.
## Installation
```
pip install django-swift-crud
```
## Usage
### Setting Up
1. **Create your Django model**:
```python
from django.db import models
class Employee(models.Model):
first_name = models.CharField(max_length=150)
last_name = models.CharField(max_length=150)
bio = models.TextField()
def __str__(self):
return f"{self.first_name} {self.last_name}"
```
2. **Define your views**:
```python
from swift_crud.views import SwiftView
from .models import Employee
from .forms import EmployeeForm # You need to create this form
class EmployeeView(SwiftView):
model = Employee
form_class = EmployeeForm
verbose_name = 'employee'
verbose_name_plural = 'employees'
template_folder = 'employees'
redirect_url = '/employees/'
allowed_views = ["list", "detail", "delete", "create", "update"]
```
3. **URL Configuration**:
The patterns in the (create, update, delete) URLs should contain the (create, update, 'delete) words, respectively (you can override this in the `get_view_method` or in the `dispatch` method):
```python
from django.urls import path
from .views import EmployeeView
urlpatterns = [
path('employees/', EmployeeView.as_view(), name='employee_list'),
path('employees/create/', EmployeeView.as_view(), name='employee_create'),
path('employees/<int:pk>/', EmployeeView.as_view(), name='employee_detail'),
path('employees/<int:pk>/update/', EmployeeView.as_view(), name='employee_update'),
path('employees/<int:pk>/delete/', EmployeeView.as_view(), name='employee_delete'),
]
```
Alternatively, you can use the `generate_crud_urls` function from the `swift_crud.utils` module:
```python
from django.urls import path, include
from .views import EmployeeView
from swift_crud.utils import generate_crud_urls
urlpatterns = [
path('', include(generate_crud_urls(EmployeeView)))
]
```
You can also add custom URL patterns by passing the `custom_patterns` parameter to `generate_crud_urls`.
## Create Your Own `SwiftView`
You can customize the `SwiftView` class if you want to add more features or Mixin classes, such as the `LoginRequiredMixin`, and reuse your custom `SwiftView` class.
## Attributes
The `SwiftView` class supports the following attributes:
- `model`: The model associated with this view. If not provided, the `get_model` method will raise a `ValueError`.
- `verbose_name` (Optional): The context variable name for a single object. If not provided, it defaults to the model's verbose name.
- `verbose_name_plural` (Optional): The context variable name for a queryset of objects. If not provided, it defaults to the model's verbose name plural.
- `template_folder`: Path to the folder of your templates.
- `custom_templates` (Optional): A dictionary to provide custom template paths.
- `redirect_url`: The URL to redirect to.
- `queryset` (Optional): The queryset to use. If not provided, `self.model.objects.all()` will be the query.
- `pk_url_kwarg` (Optional): The URL keyword argument for the primary key.
- `paginate_by` (Optional): Number of items per page for pagination.
## Contributing
If you find any bugs or have feature requests, please open an issue on GitHub. Contributions are welcome!
## License
This project is licensed under the MIT License. See the LICENSE file for details.
## Acknowledgements
This package was inspired by the need to quickly set up CRUD operations for Django models with minimal boilerplate code. Special thanks to the Django community for their continuous support and contributions.
Raw data
{
"_id": null,
"home_page": "https://github.com/khaledsukkar2/django-simple-crud",
"name": "django-swift-crud",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "django CRUD views mixins",
"author": "Khaled Sukkar",
"author_email": "khaled.sukkar.contact@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/15/e1/dc829252139f4f77bc2ce7a9aa2855d0a3a72375f45b9eb3287eb3db3e9c/django_swift_crud-0.1.2.tar.gz",
"platform": "any",
"description": "# DJANGO-SWIFT-CRUD Package\n\n## Motiviation\nCreating CRUD operations for Django models can often be a tedious, especially when dealing with the complexities of Class-Based Views. With the swift_crud package, we provide a streamlined solution that eliminates the need to navigate through inheritance hierarchies and override methods. Our goal is to empower developers to quickly and efficiently set up CRUD operations for any Django model with just one view class, saving valuable time and ensuring a smoother development process. Let swift_crud simplify your workflow and enhance your productivity.\n\n## Overview\n\nThe `swift_crud` package provides a base view class (`SwiftView`) and utility functions to quickly set up CRUD (Create, Read, Update, Delete) operations for any Django model with only one view class. This package aims to simplify the process by abstracting away the complexity of built-in Class-Based Views (CBVs) and the need to track the inheritance hierarchy to determine where to override methods.\n\nThe package includes several mixins to handle common tasks, such as:\n\n- Rendering templates\n- Managing redirects\n- Handling querysets\n- Processing forms\n\nBy utilizing these mixins, developers can easily implement CRUD functionality for their Django models without having to write boilerplate code or navigate the intricate details of the CBV.\n\n## Installation\n\n```\npip install django-swift-crud\n```\n\n## Usage\n\n### Setting Up\n\n1. **Create your Django model**:\n\n ```python\n from django.db import models\n\n class Employee(models.Model):\n first_name = models.CharField(max_length=150)\n last_name = models.CharField(max_length=150)\n bio = models.TextField()\n\n def __str__(self):\n return f\"{self.first_name} {self.last_name}\"\n ```\n\n2. **Define your views**:\n\n ```python\n from swift_crud.views import SwiftView\n from .models import Employee\n from .forms import EmployeeForm # You need to create this form\n\n class EmployeeView(SwiftView):\n model = Employee\n form_class = EmployeeForm\n verbose_name = 'employee'\n verbose_name_plural = 'employees'\n template_folder = 'employees'\n redirect_url = '/employees/'\n allowed_views = [\"list\", \"detail\", \"delete\", \"create\", \"update\"]\n ```\n\n3. **URL Configuration**:\n\n The patterns in the (create, update, delete) URLs should contain the (create, update, 'delete) words, respectively (you can override this in the `get_view_method` or in the `dispatch` method):\n\n ```python\n from django.urls import path\n from .views import EmployeeView\n\n urlpatterns = [\n path('employees/', EmployeeView.as_view(), name='employee_list'),\n path('employees/create/', EmployeeView.as_view(), name='employee_create'),\n path('employees/<int:pk>/', EmployeeView.as_view(), name='employee_detail'),\n path('employees/<int:pk>/update/', EmployeeView.as_view(), name='employee_update'),\n path('employees/<int:pk>/delete/', EmployeeView.as_view(), name='employee_delete'),\n ]\n ```\n\n Alternatively, you can use the `generate_crud_urls` function from the `swift_crud.utils` module:\n\n ```python\n from django.urls import path, include\n from .views import EmployeeView\n from swift_crud.utils import generate_crud_urls\n\n urlpatterns = [\n path('', include(generate_crud_urls(EmployeeView)))\n ]\n ```\n\n You can also add custom URL patterns by passing the `custom_patterns` parameter to `generate_crud_urls`.\n\n## Create Your Own `SwiftView`\n\nYou can customize the `SwiftView` class if you want to add more features or Mixin classes, such as the `LoginRequiredMixin`, and reuse your custom `SwiftView` class.\n\n## Attributes\n\nThe `SwiftView` class supports the following attributes:\n\n- `model`: The model associated with this view. If not provided, the `get_model` method will raise a `ValueError`.\n- `verbose_name` (Optional): The context variable name for a single object. If not provided, it defaults to the model's verbose name.\n- `verbose_name_plural` (Optional): The context variable name for a queryset of objects. If not provided, it defaults to the model's verbose name plural.\n- `template_folder`: Path to the folder of your templates.\n- `custom_templates` (Optional): A dictionary to provide custom template paths.\n- `redirect_url`: The URL to redirect to.\n- `queryset` (Optional): The queryset to use. If not provided, `self.model.objects.all()` will be the query.\n- `pk_url_kwarg` (Optional): The URL keyword argument for the primary key.\n- `paginate_by` (Optional): Number of items per page for pagination.\n\n## Contributing\n\nIf you find any bugs or have feature requests, please open an issue on GitHub. Contributions are welcome!\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Acknowledgements\n\nThis package was inspired by the need to quickly set up CRUD operations for Django models with minimal boilerplate code. Special thanks to the Django community for their continuous support and contributions.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Django package to simplify CRUD operations using a base view class.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/khaledsukkar2/django-simple-crud"
},
"split_keywords": [
"django",
"crud",
"views",
"mixins"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10c2ba62176f3e24b180c1f50476b4108ad6558cc21a86fb0a11bde7275f20c0",
"md5": "b57efac04af5b398dbcaeff5118a37a1",
"sha256": "23c4e81482c5a34878eaa21a23a87bb491bc8d5a526cd671c4d7e15c7f51af0f"
},
"downloads": -1,
"filename": "django_swift_crud-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b57efac04af5b398dbcaeff5118a37a1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 16680,
"upload_time": "2024-07-16T19:02:34",
"upload_time_iso_8601": "2024-07-16T19:02:34.181367Z",
"url": "https://files.pythonhosted.org/packages/10/c2/ba62176f3e24b180c1f50476b4108ad6558cc21a86fb0a11bde7275f20c0/django_swift_crud-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "15e1dc829252139f4f77bc2ce7a9aa2855d0a3a72375f45b9eb3287eb3db3e9c",
"md5": "63a45236107cc98b5faa97001fcc5a48",
"sha256": "7aa00b04fca207ea1b4ba84fcdf74adcb9ad1ed081d4af20b301773b64762996"
},
"downloads": -1,
"filename": "django_swift_crud-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "63a45236107cc98b5faa97001fcc5a48",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13505,
"upload_time": "2024-07-16T19:02:47",
"upload_time_iso_8601": "2024-07-16T19:02:47.498010Z",
"url": "https://files.pythonhosted.org/packages/15/e1/dc829252139f4f77bc2ce7a9aa2855d0a3a72375f45b9eb3287eb3db3e9c/django_swift_crud-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-16 19:02:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "khaledsukkar2",
"github_project": "django-simple-crud",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "django-swift-crud"
}