A custom Django model field that allows users to select icons from a predefined set.
Project description
Django Icon Picker README
Overview
Django Icon Picker is a custom Django model field that allows users to select icons from a predefined set. It supports both SVG icons and icon IDs, depending on the configuration.
Features
- SVG File Support: If the
ICON_PICKER_PATHis defined in your Django settings, the Icon Picker will download the selected SVG file and save it to the specified path. The path to the saved SVG file will be stored in thein=confield of the form. - Icon ID Support: If the
ICON_PICKER_PATHis not defined, the Icon Picker will store the ID of the selected icon in theiconfield. - Easy Integration: Use the
IconPickerwidget as a model field widget in your Django forms.
Screenshot
Usage
Step 1: Install Django Icon Picker
First, ensure you have Django Icon Picker installed in your project. If not, you can install it using pip:
pip install django-icon-picker
Add django_icon_picker to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
# Other installed apps,
'django_icon_picker',
]
Update url.py, required for download svg file case
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path("admin/", admin.site.urls),
path("icon_picker/", include("django_icon_picker.urls")),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Step 2: Configure Django Settings
If you want to use SVG files, define the ICON_PICKER_PATH in your Django settings. This is the path where the SVG files will be saved.
# settings.py
ICON_PICKER_PATH = 'media'
# default icon color
ICON_PICKER_COLOR = "#00bcc9"
Step 3: Use IconField on your model
from django.db import models
from django_icon_picker.field import IconField
from django.utils.html import format_html
class ExampleModel(models.Model):
icon = IconField(max_length=255)
name = models.CharField(max_length=255)
def svg_icon(self):
return format_html(
'<img src="{}" height="30" width="30"/>'.format(
f"/{self.icon}"
if self.icon.endswith(".svg")
else f"https://api.iconify.design/{self.icon}.svg"
)
)
def __str__(self):
return self.icon
Conclusion
Django Icon Picker provides a simple and effective way to include icon selection functionality in your Django forms. Whether you need to work with SVG files or icon IDs, this widget has you covered.
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_icon_picker-1.0.2.tar.gz.
File metadata
- Download URL: django_icon_picker-1.0.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc7128928d43cb6a1e2f7accc6bffb6f9d8eb0ba34b29dfb934800e26402e5ee
|
|
| MD5 |
a2262bd3b3e3a4ea4ddb1243d4d6b590
|
|
| BLAKE2b-256 |
5d113bf851031a59e268e14ee5375c85a64a935b8b60a6983b0d9e2f674570d5
|
File details
Details for the file django_icon_picker-1.0.2-py3-none-any.whl.
File metadata
- Download URL: django_icon_picker-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e13cdfffd402832269a72029a40cb8af32f85451e5e10a89b408005c467f5cd1
|
|
| MD5 |
71bb69e87f1e5ce164e5ed13d5e53c6d
|
|
| BLAKE2b-256 |
68f9a0a7aca478cdb8e0b75e24c5dbccadc05d80c2c9d14ffbe17fe696a7fdd9
|