# Annotation

**Annotation:** Annotation is used to add extra information to each record in a queryset. You can add calculated fields to the records in the queryset without changing the underlying data in the database.

Let's say we want to annotate each `Order` object with the number of items in that order:

```
from django.db.models import F
from myapp.models import Order, OrderItem

# Annotate each order with the count of items
orders_with_item_count = Order.objects.annotate(item_count=Count('orderitem'))

for order in orders_with_item_count:
    print(f"Order #{order.id} has {order.item_count} items.")

```

In this example, we're using the `annotate` method to add an `item_count` field to each `Order` object. This field is calculated based on the related `OrderItem` records associated with each order.

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olee-tech.gitbook.io/django/django-orm/basic-database-operation/annotation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
