What is the **recommended way** to **store a Python exception** – in a structured way that allows access to the different parts of that exception – **in a Django model**?

It is common to design a Django model that records “an event” or “an attempt to do foo”; part of the information to be recorded is “… and the result was this error”. That then becomes a field on the model.

An important aspect of recording the error in the database is to query it in various structured ways: What was the exception type? What was the specific message? What were the other arguments to the exception instance? What was the full traceback?

(I'm aware of services that will let me stream logging or errors to them across the network; that is *not* what this question asks. I need the structured exception data in the project's own database, for reference directly from other models in the same database.)

The [Python exception object](https://docs.python.org/3/library/exceptions.html) is a data structure that has all of these parts – the exception type, the arguments to the exception instance, the “cause” and “context”, the traceback – available separately, as attributes of the object. The objective of this question is to have the Python exception information stored in the database model, such that they can be queried in an equivalent structured manner.

So it isn't enough to have a free-form TextField to record a string representation of the exception. A structured field or set of fields is needed; perhaps even an entire separate model for storing exception instances.

Of course I could design such a thing myself, and spend time making the same mistakes countless people before me have undoubtedly made in trying to implement something like this. Instead, I want to learn from existing art in solving this problem.

What is a general pattern to **store structured Python exception data in a Django model, preferably in an existing mature general-purpose library** at PyPI that my project can use for its models?