0
0
mirror of https://github.com/django/django.git synced 2024-11-25 07:59:34 +01:00
django/tests/expressions_window/models.py
Simon Charette f387d024fc Refs #28333 -- Added partial support for filtering against window functions.
Adds support for joint predicates against window annotations through
subquery wrapping while maintaining errors for disjointed filter
attempts.

The "qualify" wording was used to refer to predicates against window
annotations as it's the name of a specialized Snowflake extension to
SQL that is to window functions what HAVING is to aggregates.

While not complete the implementation should cover most of the common
use cases for filtering against window functions without requiring
the complex subquery pushdown and predicate re-aliasing machinery to
deal with disjointed predicates against columns, aggregates, and window
functions.

A complete disjointed filtering implementation should likely be
deferred until proper QUALIFY support lands or the ORM gains a proper
subquery pushdown interface.
2022-08-15 08:26:26 +02:00

32 lines
993 B
Python

from django.db import models
class Classification(models.Model):
code = models.CharField(max_length=10)
class Employee(models.Model):
name = models.CharField(max_length=40, blank=False, null=False)
salary = models.PositiveIntegerField()
department = models.CharField(max_length=40, blank=False, null=False)
hire_date = models.DateField(blank=False, null=False)
age = models.IntegerField(blank=False, null=False)
classification = models.ForeignKey(
"Classification", on_delete=models.CASCADE, null=True
)
bonus = models.DecimalField(decimal_places=2, max_digits=15, null=True)
class PastEmployeeDepartment(models.Model):
employee = models.ForeignKey(
Employee, related_name="past_departments", on_delete=models.CASCADE
)
department = models.CharField(max_length=40, blank=False, null=False)
class Detail(models.Model):
value = models.JSONField()
class Meta:
required_db_features = {"supports_json_field"}