  .. code-block:: pycon
  
      >>> from django.db.models import Avg, F, Max, Min, Window
      >>> window = {
      >>>    'partition_by': [F('studio'), F('genre')],
      >>>    'order_by': 'released__year',
      >>> }
      >>> Movie.objects.annotate(
      >>>     avg_rating=Window(
      >>>         expression=Avg('rating'), **window,
      >>>     ),
      >>>     best=Window(
 
</s> remove     >>>     avg_rating=Window(
    >>>         expression=Avg('rating'), **window,
    >>>     ),
    >>>     best=Window(
    >>>         expression=Max('rating'), **window,
    >>>     ),
    >>>     worst=Window(
    >>>         expression=Min('rating'), **window,
    >>>     ),
    >>> )
 </s> add     ...     avg_rating=Window(
    ...         expression=Avg('rating'), **window,
    ...     ),
    ...     best=Window(
    ...         expression=Max('rating'), **window,
    ...     ),
    ...     worst=Window(
    ...         expression=Min('rating'), **window,
    ...     ),
    ... ) </s> remove     >>>     avg_rating=Window(
    >>>         expression=Avg('rating'),
    >>>         partition_by=[F('studio'), F('genre')],
    >>>         order_by='released__year',
    >>>         frame=ValueRange(start=-12, end=12),
    >>>     ),
    >>> )
 </s> add     ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=ValueRange(start=-12, end=12),
    ...     ),
    ... ) </s> remove     >>>     avg_rating=Window(
    >>>         expression=Avg('rating'),
    >>>         partition_by=[F('studio'), F('genre')],
    >>>         order_by='released__year',
    >>>     ),
    >>> )
 </s> add     ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...     ),
    ... ) </s> remove     >>>     avg_rating=Window(
    >>>         expression=Avg('rating'),
    >>>         partition_by=[F('studio'), F('genre')],
    >>>         order_by='released__year',
    >>>         frame=RowRange(start=-2, end=2),
    >>>     ),
    >>> )
 </s> add     ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... ) </s> remove     >>>     category_rank=Window(
    >>>         Rank(), partition_by='category', order_by='-rating'
    >>>     ),
    >>>     scenes_count=Count('actors'),
    >>> ).filter(
    >>>     Q(category_rank__lte=3) | Q(title__contains='Batman')
    >>> )
 </s> add     ...     category_rank=Window(
    ...         Rank(), partition_by='category', order_by='-rating'
    ...     ),
    ...     scenes_count=Count('actors'),
    ... ).filter(
    ...     Q(category_rank__lte=3) | Q(title__contains='Batman')
    ... )
    ...    'partition_by': [F('studio'), F('genre')],
    ...    'order_by': 'released__year',
    ... }
  .. code-block:: pycon
  
      >>> from django.db.models import Avg, F, Max, Min, Window
      >>> window = {
    ...    'partition_by': [F('studio'), F('genre')],
    ...    'order_by': 'released__year',
    ... }
    ...    'partition_by': [F('studio'), F('genre')],
    ...    'order_by': 'released__year',
    ... }
    ...    'partition_by': [F('studio'), F('genre')],
    ...    'order_by': 'released__year',
    ... }
      >>> Movie.objects.annotate(
      >>>     avg_rating=Window(
      >>>         expression=Avg('rating'), **window,
      >>>     ),
      >>>     best=Window(
keep keep keep keep replace replace replace keep keep keep keep keep
 Refs #34140 -- Corrected rst code-block and various formatting issues in docs. 
docs/ref/models/expressions.txt