A Image File storage field. :param size: max size to store images, provided as (width, height, force) if larger, it will be automatically resized (ex: size=(800, 600, True)) :param thumbnail_size: size to generate a thumbnail, provided as (width, height, force)
| 2039 | |
| 2040 | |
| 2041 | class ImageField(FileField): |
| 2042 | """ |
| 2043 | A Image File storage field. |
| 2044 | |
| 2045 | :param size: max size to store images, provided as (width, height, force) |
| 2046 | if larger, it will be automatically resized (ex: size=(800, 600, True)) |
| 2047 | :param thumbnail_size: size to generate a thumbnail, provided as (width, height, force) |
| 2048 | """ |
| 2049 | |
| 2050 | proxy_class = ImageGridFsProxy |
| 2051 | |
| 2052 | def __init__( |
| 2053 | self, size=None, thumbnail_size=None, collection_name="images", **kwargs |
| 2054 | ): |
| 2055 | if not Image: |
| 2056 | raise ImproperlyConfigured("PIL library was not found") |
| 2057 | |
| 2058 | params_size = ("width", "height", "force") |
| 2059 | extra_args = {"size": size, "thumbnail_size": thumbnail_size} |
| 2060 | for att_name, att in extra_args.items(): |
| 2061 | value = None |
| 2062 | if isinstance(att, (tuple, list)): |
| 2063 | value = dict(itertools.zip_longest(params_size, att, fillvalue=None)) |
| 2064 | |
| 2065 | setattr(self, att_name, value) |
| 2066 | |
| 2067 | super().__init__(collection_name=collection_name, **kwargs) |
| 2068 | |
| 2069 | |
| 2070 | class SequenceField(BaseField): |