Repository: django/django
File: tests/ordering/models.py (Python)

Code before:
    name = models.CharField(max_length=30)

    class Meta:
        ordering = [models.functions.Lower("name")]


class OrderedByExpressionChild(models.Model):
    parent = models.ForeignKey(OrderedByExpression, models.CASCADE)

    class Meta:
        ordering = ["parent"]


class OrderedByExpressionGrandChild(models.Model):
    parent = models.ForeignKey(OrderedByExpressionChild, models.CASCADE)


class OrderingConstraint(models.Model):
    rank = models.IntegerField(unique=True, null=True)
    headline = models.CharField(max_length=100)
    slug = models.CharField(max_length=100, default="slug")
    author = models.ForeignKey(Author, on_delete=models.CASCADE, null=True)
    pub_date = models.DateField(null=True)
    editor = models.OneToOneField(
        Author, on_delete=models.CASCADE, related_name="ordering_constraint_editor"
    )
    barcode = models.CharField(max_length=30, default="bar")

    class Meta:
        unique_together = (("headline", "slug"),)
        constraints = [
            models.UniqueConstraint(
                fields=["pub_date", "author"],
                name="unique_pub_date_author",
            ),
            models.UniqueConstraint(
                fields=["rank"],
                condition=models.Q(rank__gt=0),
                name="unique_rank_conditional",
            ),
            models.UniqueConstraint(
                fields=["barcode"],
                condition=models.Q(),
                name="unique_barcode_empty_condition",
            ),
        ]


Review comment (refactor):
On some databases, I'm getting a warning.
```
ordering.OrderingConstraint: (models.W036) MariaDB does not support unique constraints with conditions.
        HINT: A constraint won't be created. Silence this warning if you don't care about it.
```
I think you need in this class's `Meta`:
```py
required_db_features = {"supports_partial_indexes"}
```
And then reorganize the tests that use this model to be all skipped with `@skipUnlessDBFeature("supports_partial_indexes")`

Code after:
class OrderedByExpression(models.Model):
    name = models.CharField(max_length=30)

    class Meta:
        ordering = [models.functions.Lower("name")]


class OrderedByExpressionChild(models.Model):
    parent = models.ForeignKey(OrderedByExpression, models.CASCADE)

    class Meta:
        ordering = ["parent"]


class OrderedByExpressionGrandChild(models.Model):
    parent = models.ForeignKey(OrderedByExpressionChild, models.CASCADE)


class BarcodedArticle(models.Model):
    rank = models.IntegerField(unique=True, null=True)
    headline = models.CharField(max_length=100)
    slug = models.CharField(max_length=100, default="slug")
    pub_date = models.DateField(null=True)
    barcode = models.CharField(max_length=30, default="bar")

    class Meta:
        required_db_features = {"supports_partial_indexes"}
        unique_together = (("headline", "slug"),)
        constraints = [
            models.UniqueConstraint(
                fields=["pub_date", "rank"],
                name="unique_pub_date_rank",
            ),
            models.UniqueConstraint(
                fields=["rank"],
                condition=models.Q(rank__gt=0),
                name="unique_rank_conditional",
            ),
            models.UniqueConstraint(
                fields=["barcode"],
                condition=models.Q(),
                name="unique_barcode_empty_condition",
            ),
        ]