Debian Codegraph @

README.md

raw symbols SCIP
1 [![](https://img.shields.io/pypi/pyversions/django-colorfield.svg?color=3776AB&logo=python&logoColor=white)](https://www.python.org/)
2 [![](https://img.shields.io/pypi/djversions/django-colorfield?color=0C4B33&logo=django&logoColor=white&label=django)](https://www.djangoproject.com/)
3
4 [![](https://img.shields.io/pypi/v/django-colorfield.svg?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/django-colorfield/)
5 [![](https://static.pepy.tech/badge/django-colorfield/month)](https://pepy.tech/project/django-colorfield)
6 [![](https://img.shields.io/github/stars/fabiocaccamo/django-colorfield?logo=github)](https://github.com/fabiocaccamo/django-colorfield/stargazers)
7 [![](https://img.shields.io/pypi/l/django-colorfield.svg?color=blue)](https://github.com/fabiocaccamo/django-colorfield/blob/main/LICENSE.txt)
8
9 [![](https://results.pre-commit.ci/badge/github/fabiocaccamo/django-colorfield/main.svg)](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-colorfield/main)
10 [![](https://img.shields.io/github/actions/workflow/status/fabiocaccamo/django-colorfield/test-package.yml?branch=main&label=build&logo=github)](https://github.com/fabiocaccamo/django-colorfield)
11 [![](https://img.shields.io/codecov/c/gh/fabiocaccamo/django-colorfield?logo=codecov)](https://codecov.io/gh/fabiocaccamo/django-colorfield)
12 [![](https://img.shields.io/codacy/grade/194566618f424a819ce43450ea0af081?logo=codacy)](https://www.codacy.com/app/fabiocaccamo/django-colorfield)
13 [![](https://img.shields.io/codeclimate/maintainability/fabiocaccamo/django-colorfield?logo=code-climate)](https://codeclimate.com/github/fabiocaccamo/django-colorfield/)
14 [![](https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=black)](https://github.com/psf/black)
15 [![](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
16
17 # django-colorfield
18 simple color field for your models with a nice color-picker in the admin-interface.
19
20 ![django-colorfield-hex](https://user-images.githubusercontent.com/7900305/104512324-51ed0f80-55ee-11eb-9144-de03d922c2ce.png)
21 ![django-colorfield-hexa](https://user-images.githubusercontent.com/7900305/104512063-ec991e80-55ed-11eb-95b6-9174ac3f4f38.png)
22
23 ---
24
25 ## Installation
26 - Run `pip install django-colorfield`
27 - Add `colorfield` to `settings.INSTALLED_APPS`
28 - Run `python manage.py collectstatic`
29 - Restart your application server
30
31 ---
32
33 ## Usage
34
35 ### Settings
36 This package doesn't need any setting.
37
38 ### Models
39 Just add color field(s) to your models like this:
40
41 ```python
42 from colorfield.fields import ColorField
43 from django.db import models
44
45 class MyModel(models.Model):
46 color = ColorField(default='#FF0000')
47 ```
48
49 ### Field Options
50 These are the supported custom options: [`format`](#format), [`image_field`](#image_field), [`samples`](#samples)
51
52 #### format
53
54 The following formats are supported: `hex` *(default)*, `hexa`, `rgb`, `rgba`.
55
56 ```python
57 from colorfield.fields import ColorField
58 from django.db import models
59
60 class MyModel(models.Model):
61 color = ColorField(format="hexa")
62 ```
63
64 #### image_field
65
66 It is possible to auto-populate the field value getting the color from an image using the `image_field` option.
67
68 The color will be calculated from the **top-left pixel** color of the image each time the model instance is saved.
69
70 ```python
71 from colorfield.fields import ColorField
72 from django.db import models
73
74 class MyModel(models.Model):
75 image = models.ImageField(upload_to="images")
76 color = ColorField(image_field="image")
77 ```
78
79 #### samples
80
81 It is possible to provide a palette of colors to choose from to the widget using the `samples` option.
82
83 This option **is not restrictive** (on the contrary of `choices` option), it is also possible to choose another color from the spectrum.
84
85 ![django-colorfield-samples](https://user-images.githubusercontent.com/7900305/104512178-194d3600-55ee-11eb-8cba-91cca156da06.png)
86
87 ```python
88 from colorfield.fields import ColorField
89 from django.db import models
90
91 class MyModel(models.Model):
92
93 COLOR_PALETTE = [
94 ("#FFFFFF", "white", ),
95 ("#000000", "black", ),
96 ]
97
98 # not restrictive, allows the selection of another color from the spectrum.
99 color = ColorField(samples=COLOR_PALETTE)
100
101 # restrictive, it is mandatory to choose a color from the palette
102 color = ColorField(choices=COLOR_PALETTE)
103 ```
104
105 ### Admin
106 The admin will kindly provide a simple [color picker](http://jscolor.com/) for all color fields. :)
107
108 ---
109
110 ## Testing
111 ```bash
112 # clone repository
113 git clone https://github.com/fabiocaccamo/django-colorfield.git && cd django-colorfield
114
115 # create virtualenv and activate it
116 python -m venv venv && . venv/bin/activate
117
118 # upgrade pip
119 python -m pip install --upgrade pip
120
121 # install requirements
122 pip install -r requirements.txt -r requirements-test.txt
123
124 # install pre-commit to run formatters and linters
125 pre-commit install --install-hooks
126
127 # run tests
128 tox
129 # or
130 python runtests.py
131 # or
132 python -m django test --settings "tests.settings"
133 ```
134 ---
135
136 ## Credits
137 Originally developed by [Jared Forsyth](https://github.com/jaredly)
138
139 ---
140
141 ## License
142 Released under [MIT License](LICENSE.txt).
143
144 ---
145
146 ## Supporting
147
148 - :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-colorfield)
149 - :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)
150 - :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)
151 - :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)
152
153 ## See also
154
155 - [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. ๐Ÿง™ โšก
156
157 - [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. โš™๏ธ
158
159 - [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. ๐Ÿšง ๐Ÿ› ๏ธ
160
161 - [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. โ†ช๏ธ
162
163 - [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. ๐ŸŒณ
164
165 - [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. ๐Ÿ“˜
166
167 - [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ’ณ
168
169 - [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. ๐Ÿงข
170
171 - [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. ๐ŸงŸโ€โ™‚๏ธ