# django-imgwidget
[![GitHub License](https://img.shields.io/github/license/RelaxedDong/django_imguploder)](https://opensource.org/licenses/MIT)
[![PyPI Version](https://img.shields.io/pypi/v/django-imgwidget)](https://pypi.org/project/django-imgwidget)
**django-imgwidget** is a Django package that provides easy and efficient image uploading in the admin site. It supports single-image uploads as well as batch uploads for multiple images. The package comes with features like large image preview, image deletion, and image rotation preview.
## Features
- Save as json or string to a field
- Single-image and batch upload support.
- Large image preview with the ability to delete images.
- Image rotation preview for a better viewing experience.
- Keyboard shortcuts for enhanced user experience.
## Installation
Install the package using pip:
```bash
pip install django-imgwidget
-----
👍 后台上传图片
⚡️ 单图片、多图片批量上传
✨ 图片大图预览、删除
🐰 图片旋转预览
🔥 支持键盘快捷操作
1.支持左右键切换预览图片
2.支持ESC退出预览模式
```
🌈 效果图片
![img_3.png](img_3.png)
![img_1.png](img_1.png)!
Installation
-----
`pip install django-imgwidget`
`Homepage: https://pypi.org/project/django-imgwidget`
Steps
-----
- Add `django_imguploder` to your settings.py
- Configure the image upload route, route name is `upload_image`
```python
path("upload", ImageUploadView.as_view(), name='upload_image')
```
- Write a view function.
Need to return JsonResponse `image_list error_msg`, if there are errors, return error_msg error prompt. example:
```python
class ImageUploadView(views.View):
def post(self, request):
files = request.FILES or {}
image_list = [upload_img(file) for file in list(files.values())]
return JsonResponse({
"error_msg": "",
"image_list": image_list,
})
```
- Use the MultiImageField in admin.py
```python
# models.py
class MyModel(models.Model):
imgs = models.TextField(default=[], null=False, verbose_name='图片')
description = models.CharField(verbose_name="描述", null="", max_length=100)
# admin.py
class UploadImgsForm(ModelForm):
imgs = MultiImageField(label="imgs", max_count=13, required=False)
description_img = MultiImageField(label="description", max_count=1, required=False, save_json_list=False)
class CameraAdmin(admin.ModelAdmin):
fieldsets = [
('information', {'fields': (
('imgs',),
('description_img',),
)}),
]
form = UploadImgsForm
# result: imgs -> '["1.jpeg", "2.jpg"]', description -> description_img.jpeg
```
### Configuration:
```html
accept:
config <input> accept
max_count:
Description: Defines the maximum number of files that can be selected/uploaded using the file input.
save_json_list:
Description: Determines whether the uploaded file names are saved as a JSON-formatted list or string.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/RelaxedDong/django_imguploder",
"name": "django-imgwidget",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django,admin,widget,image,uploader",
"author": "donghao",
"author_email": "1417766861@qq.com",
"download_url": "https://files.pythonhosted.org/packages/69/e1/9bd96acc9eca66d05bda4bb9a01bd8170d3dd46e02dd50f05ef9f6b47d68/django-imgwidget-0.0.6.tar.gz",
"platform": null,
"description": "# django-imgwidget\n\n[![GitHub License](https://img.shields.io/github/license/RelaxedDong/django_imguploder)](https://opensource.org/licenses/MIT)\n[![PyPI Version](https://img.shields.io/pypi/v/django-imgwidget)](https://pypi.org/project/django-imgwidget)\n\n**django-imgwidget** is a Django package that provides easy and efficient image uploading in the admin site. It supports single-image uploads as well as batch uploads for multiple images. The package comes with features like large image preview, image deletion, and image rotation preview.\n\n## Features\n- Save as json or string to a field\n- Single-image and batch upload support.\n- Large image preview with the ability to delete images.\n- Image rotation preview for a better viewing experience.\n- Keyboard shortcuts for enhanced user experience.\n\n## Installation\n\nInstall the package using pip:\n\n```bash\npip install django-imgwidget\n\n\n-----\n\ud83d\udc4d \u540e\u53f0\u4e0a\u4f20\u56fe\u7247\n\n\u26a1\ufe0f \u5355\u56fe\u7247\u3001\u591a\u56fe\u7247\u6279\u91cf\u4e0a\u4f20\n\n\u2728 \u56fe\u7247\u5927\u56fe\u9884\u89c8\u3001\u5220\u9664\n\n\ud83d\udc30 \u56fe\u7247\u65cb\u8f6c\u9884\u89c8\n\n\ud83d\udd25 \u652f\u6301\u952e\u76d8\u5feb\u6377\u64cd\u4f5c\n\n 1.\u652f\u6301\u5de6\u53f3\u952e\u5207\u6362\u9884\u89c8\u56fe\u7247\n \n 2.\u652f\u6301ESC\u9000\u51fa\u9884\u89c8\u6a21\u5f0f\n```\n\n\ud83c\udf08 \u6548\u679c\u56fe\u7247\n\n![img_3.png](img_3.png)\n\n![img_1.png](img_1.png)!\n\nInstallation\n-----\n`pip install django-imgwidget`\n\n`Homepage: https://pypi.org/project/django-imgwidget`\n\nSteps\n-----\n- Add `django_imguploder` to your settings.py\n\n- Configure the image upload route, route name is `upload_image`\n\n```python\npath(\"upload\", ImageUploadView.as_view(), name='upload_image')\n```\n\n- Write a view function.\nNeed to return JsonResponse `image_list error_msg`, if there are errors, return error_msg error prompt. example:\n```python \nclass ImageUploadView(views.View):\n def post(self, request):\n files = request.FILES or {}\n image_list = [upload_img(file) for file in list(files.values())]\n return JsonResponse({\n \"error_msg\": \"\",\n \"image_list\": image_list,\n })\n```\n\n- Use the MultiImageField in admin.py\n\n```python\n# models.py\nclass MyModel(models.Model):\n imgs = models.TextField(default=[], null=False, verbose_name='\u56fe\u7247')\n description = models.CharField(verbose_name=\"\u63cf\u8ff0\", null=\"\", max_length=100)\n \n# admin.py \nclass UploadImgsForm(ModelForm):\n imgs = MultiImageField(label=\"imgs\", max_count=13, required=False)\n description_img = MultiImageField(label=\"description\", max_count=1, required=False, save_json_list=False)\n\n\nclass CameraAdmin(admin.ModelAdmin):\nfieldsets = [\n ('information', {'fields': (\n ('imgs',),\n ('description_img',),\n )}),\n]\nform = UploadImgsForm\n\n# result: imgs -> '[\"1.jpeg\", \"2.jpg\"]', description -> description_img.jpeg\n```\n\n\n### Configuration\uff1a\n```html\naccept:\n\nconfig <input> accept\n\nmax_count:\n\nDescription: Defines the maximum number of files that can be selected/uploaded using the file input.\n\nsave_json_list:\nDescription: Determines whether the uploaded file names are saved as a JSON-formatted list or string.\n```\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "\u4e0a\u4f20\u56fe\u7247\u7ec4\u4ef6",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/RelaxedDong/django_imguploder"
},
"split_keywords": [
"django",
"admin",
"widget",
"image",
"uploader"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "69e19bd96acc9eca66d05bda4bb9a01bd8170d3dd46e02dd50f05ef9f6b47d68",
"md5": "ace9361f1d8e69659fb66c56a4b0e8ba",
"sha256": "a5efd4b996740ab32dab443de6617413fa8fba652bc8914c67fcc2918c16a47e"
},
"downloads": -1,
"filename": "django-imgwidget-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "ace9361f1d8e69659fb66c56a4b0e8ba",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 56721,
"upload_time": "2023-12-25T09:11:36",
"upload_time_iso_8601": "2023-12-25T09:11:36.099902Z",
"url": "https://files.pythonhosted.org/packages/69/e1/9bd96acc9eca66d05bda4bb9a01bd8170d3dd46e02dd50f05ef9f6b47d68/django-imgwidget-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-25 09:11:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RelaxedDong",
"github_project": "django_imguploder",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-imgwidget"
}