1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #19215 -- Fixed admin_widgets tests if Pillow isn't installed.

Follow up to c0fc1b5302.
This commit is contained in:
Mariusz Felisiak
2022-10-27 08:41:03 +02:00
committed by GitHub
parent eb6cc01d0f
commit d559cb02da
2 changed files with 14 additions and 5 deletions

View File

@@ -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",)