Skip to content

Commit f93e7dc

Browse files
Make default color for django.ImageField random
1 parent d6349de commit f93e7dc

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.pyc
44
*.pyo
55
.idea/
6+
.venv/
67

78
# Build-related files
89
docs/_build/

factory/django.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import os
1111
import warnings
12+
import random
1213
from typing import Dict, TypeVar
1314

1415
from django.contrib.auth.hashers import make_password
@@ -258,11 +259,13 @@ class ImageField(FileField):
258259
def _make_data(self, params):
259260
# ImageField (both django's and factory_boy's) require PIL.
260261
# Try to import it along one of its known installation paths.
261-
from PIL import Image
262+
from PIL import Image, ImageColor
262263

263264
width = params.get('width', 100)
264265
height = params.get('height', width)
265-
color = params.get('color', 'blue')
266+
color = params.get('color', random.choice( # noqa: S311
267+
list(ImageColor.colormap.keys()),
268+
))
266269
image_format = params.get('format', 'JPEG')
267270
image_palette = params.get('palette', 'RGB')
268271

0 commit comments

Comments
 (0)