<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update(self):
 """Update the cart. First this method updates attributes dependent on the cart's `items`, such as `total_price` or `item_count`. After that, it saves the new cart state to the session. Generally, you'll need to call this method by yourself, only when implementing new methods that directly change the `items` attribute. """

        self.item_count = self.count_items()
        self.total_price = self.count_total_price()
        # Update the session
        session = self.request.session
        session_items = {}
        for pk, item in self.items.items():
            session_items[pk] = dict(quantity=item.quantity, **item._kwargs)
        session_data = session[session_key]
        session_data['items'] = session_items
        session_data['itemCount'] = self.item_count
        # The price can be of a type that can't be serialized to JSON
        session_data['totalPrice'] = str(self.total_price)
        session.modified = True