  .. code-block:: pycon
  
      >>> from django.db.models import Avg, F, RowRange, Window
      >>> Movie.objects.annotate(
      >>>     avg_rating=Window(
      >>>         expression=Avg('rating'),
      >>>         partition_by=[F('studio'), F('genre')],
      >>>         order_by='released__year',
      >>>         frame=RowRange(start=-2, end=2),
      >>>     ),
      >>> )
  
  If the database supports it, you can specify the start and end points based on
  values of an expression in the partition. If the ``released`` field of the
  ``Movie`` model stores the release month of each movies, this ``ValueRange``
  example annotates each movie with the average rating of a movie's peers
 
</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=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     >>>    'partition_by': [F('studio'), F('genre')],
    >>>    'order_by': 'released__year',
    >>> }
 </s> add     ...    'partition_by': [F('studio'), F('genre')],
    ...    'order_by': 'released__year',
    ... } </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 .. code-block:: pycon
 </s> add .. code-block:: text
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
  .. code-block:: pycon
  
      >>> from django.db.models import Avg, F, RowRange, Window
      >>> Movie.objects.annotate(
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
    ...     avg_rating=Window(
    ...         expression=Avg('rating'),
    ...         partition_by=[F('studio'), F('genre')],
    ...         order_by='released__year',
    ...         frame=RowRange(start=-2, end=2),
    ...     ),
    ... )
  
  If the database supports it, you can specify the start and end points based on
  values of an expression in the partition. If the ``released`` field of the
  ``Movie`` model stores the release month of each movies, this ``ValueRange``
  example annotates each movie with the average rating of a movie's peers
keep keep keep keep replace replace replace replace 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