{"repo":"jonathan-s/djantic2","free":true,"listed":false,"github":"https://github.com/jonathan-s/djantic2","clone":"git clone https://github.com/jonathan-s/djantic2.git","description":"Pydantic model support for Django","language":"Python","stars":92,"topics":["django","pydantic","pydantic-v2"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Djantic2 Pydantic model support for Django --- Djantic2 is a fork of djantic which works with pydantic 2, it is a library that provides a configurable utility class for automatically creating a Pydantic model instance for any Django model class. It is intended to support all of the underlying Pydantic model functionality such as JSON schema generation and introduces custom behaviour for exporting Django model instance data. Quickstart Install using pip: Create a model schema: Output: See https://pydantic-docs.helpmanual.io/usage/models/ for more. Loading and exporting model instances Use the from django method on the model schema to load a Django model instance for export : Output: Using multiple level relations Djantic supports multiple level relations. This includes foreign keys, many-to-many, and one-to-one relationships. Consider the following example Django model and Djantic model schema definitions for a number of related database records: Now let's assume you're interested in exporting the order and profile information for a particular user into a JSON format that contains the details accross all of the related item objects: Output: The model schema definitions are composable and support customization of the output according to the auto-generated fields and any additional annotations. Including and excluding fields The fields exposed in the model instance may be configured using two options: include and exclude . These represent iterables that should contain a list of ","default_branch":null,"files":null,"tree":[],"storefront":"/r/jonathan-s","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/jonathan-s/djantic2/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}