diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-10-27 08:41:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-27 08:41:03 +0200 |
| commit | d559cb02da30f74debbb1fc3a46de0df134d2d80 (patch) | |
| tree | e4f3dab1c7a1f28e3209dfc10e09e6c58cd1da33 /tests/admin_widgets/models.py | |
| parent | eb6cc01d0f62c73441a3610193ba210176d0935f (diff) | |
Refs #19215 -- Fixed admin_widgets tests if Pillow isn't installed.
Follow up to c0fc1b5302f5d9d82e2255fb5758321fbac34949.
Diffstat (limited to 'tests/admin_widgets/models.py')
| -rw-r--r-- | tests/admin_widgets/models.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/admin_widgets/models.py b/tests/admin_widgets/models.py index 26eaf5d243..0113ecb7c8 100644 --- a/tests/admin_widgets/models.py +++ b/tests/admin_widgets/models.py @@ -5,8 +5,13 @@ from django.contrib.auth.models import User from django.core.files.storage import FileSystemStorage from django.db import models -temp_storage_dir = tempfile.mkdtemp() -temp_storage = FileSystemStorage(temp_storage_dir) +try: + from PIL import Image +except ImportError: + Image = None +else: + temp_storage_dir = tempfile.mkdtemp() + temp_storage = FileSystemStorage(temp_storage_dir) class MyFileField(models.FileField): @@ -182,9 +187,10 @@ class Advisor(models.Model): class Student(models.Model): name = models.CharField(max_length=255) - photo = models.ImageField( - storage=temp_storage, upload_to="photos", blank=True, null=True - ) + if Image: + photo = models.ImageField( + storage=temp_storage, upload_to="photos", blank=True, null=True + ) class Meta: ordering = ("name",) |
