Repository: wagtail/wagtail
File: wagtail/images/models.py (Python)

Code before:
        attrs.update(extra_attributes)

        return mark_safe(f"<img{flatatt(attrs)}>")

    def __html__(self):
        return self.img_tag()

    def get_upload_to(self, filename):
        """
        Generates a file path within the "images" folder by combining the folder name and the validated filename.
        """
        folder_name = "images"
        filename = self.file.field.storage.get_valid_name(filename)
        return os.path.join(folder_name, filename)

    @classmethod
    def check(cls, **kwargs):
        errors = super().check(**kwargs)
        if not cls._meta.abstract:
            in_unique_together = any(
                set(constraint) == {"image", "filter_spec", "focal_point_key"}
                for constraint in cls._meta.unique_together
            )

            # We only include fields to check if they are a UniqueConstraint, a
            # nd they have no condition on them.
            unique_constraint_fields = [
                constraint.fields
                for constraint in cls._meta.constraints
                if (
                    isinstance(constraint, UniqueConstraint)
                    and constraint.condition is None
                )
            ]
            in_unique_constraint = any(
                set(constraint) == {"image", "filter_spec", "focal_point_key"}
                for constraint in unique_constraint_fields
            )

            # We check for some kind of unique constraint, whether in unique together or
            # as part of the constraints.
            if not in_unique_together and not in_unique_constraint:
                errors.append(
                    checks.Error(
                        "Custom rendition model %r has an invalid unique_together setting"
                        % cls,
                        hint="Custom rendition models must include the constraint "
                        "('image', 'filter_spec', 'focal_point_key') in their unique_together definition, or as part of a unique constraint.",
                        obj=cls,
                        id="wagtailimages.E001",
                    )

Review comment (suggestion):
```suggestion
            # We only include fields to check if they are a UniqueConstraint, and
            # they have no condition on them.
```

Code after:
        attrs.update(extra_attributes)

        return mark_safe(f"<img{flatatt(attrs)}>")

    def __html__(self):
        return self.img_tag()

    def get_upload_to(self, filename):
        """
        Generates a file path within the "images" folder by combining the folder name and the validated filename.
        """
        folder_name = "images"
        filename = self.file.field.storage.get_valid_name(filename)
        return os.path.join(folder_name, filename)

    @classmethod
    def check(cls, **kwargs):
        errors = super().check(**kwargs)
        if not cls._meta.abstract:
            # Allow unique constraint to be defined via `unique_together` or
            # a `UniqueConstraint` in `constraints`.
            unique_constraint_fields = {"image", "filter_spec", "focal_point_key"}
            in_unique_together = any(
                set(constraint) == unique_constraint_fields
                for constraint in cls._meta.unique_together
            )
            in_unique_constraint = any(
                isinstance(constraint, models.UniqueConstraint)
                and constraint.condition is None
                and set(constraint.fields) == unique_constraint_fields
                for constraint in cls._meta.constraints
            )

            if not in_unique_together and not in_unique_constraint:
                errors.append(
                    checks.Error(
                        "Custom rendition model '%s' must include a unique constraint "
                        "on the 'image', 'filter_spec', and 'focal_point_key' fields."
                        % cls._meta.label,
                        hint=(
                            "Add models.UniqueConstraint(fields={"
                            '"image", "filter_spec", "focal_point_key"}, '
                            'name="unique_rendition") to %s.Meta.constraints.'
                            % (cls.__name__,)
                        ),
                        obj=cls,
                        id="wagtailimages.E001",
                    )
                )

        return errors