-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,319 additions
and
3,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,25 @@ | ||
# Why this package? | ||
# What | ||
|
||
# Tags | ||
SuperSchema is a library that allows to define Pydantic schemas based on Django database models. | ||
|
||
django,api,rest,json,ninja,infer,django orm, django model, pydantic, schema | ||
Similar libraries: | ||
- [Djantic](https://jordaneremieff.github.io/djantic/) | ||
- [Django Ninja Schema](https://django-ninja.dev/guides/response/django-pydantic/) | ||
- [Ninja Schema](https://github.com/eadwinCode/ninja-schema) | ||
|
||
# Key feature | ||
# Why | ||
|
||
# Usage | ||
SuperSchema is the most complete Pydantic schemas based on Django models. | ||
|
||
```python | ||
# Key features | ||
|
||
from django.db import models | ||
- Supports all Django model fields | ||
- Supports all Django model relation fields: | ||
- ForeignKey, OneToOneField, ManyToManyField | ||
- The reverse relations of the above (ManyToOneRel, OneToOneRel, ManyToManyRel) | ||
- Supports defining nested relations | ||
- Provides as complete OpenAPI schema details as possible | ||
|
||
class MyModelA(models.Model): | ||
id = models.AutoField(primary_key=True) | ||
name = models.CharField(max_length=255) | ||
description = models.TextField() | ||
# How | ||
|
||
|
||
class MyModelB(models.Model): | ||
id = models.AutoField(primary_key=True) | ||
name = models.CharField(max_length=255) | ||
organization = models.ForeignKey(MyModelA, on_delete=models.CASCADE) | ||
applications = models.ManyToManyField(MyModelA) | ||
account = models.OneToOneField(MyModelA, on_delete=models.CASCADE) | ||
|
||
``` | ||
|
||
```python | ||
|
||
|
||
# | ||
|
||
# Usage example: | ||
|
||
from superschema.types import Infer, InferExcept, ModelFields | ||
|
||
# Basic usage: | ||
|
||
model: ModelFields = { | ||
"id": Infer, | ||
"name": Infer, | ||
"description": Infer, | ||
"organization": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
"applications": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
"account": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
} | ||
|
||
# Overriding some inferred details | ||
|
||
from superschema.types import InferExcept | ||
|
||
list_fields: ModelFields = { | ||
"name": InferExcept(description="I was not happy what was inferred so I defined here."), | ||
} | ||
|
||
# Allows also to use the native Pydantic FieldInfo | ||
|
||
from pydantic import Field | ||
|
||
list_fields: ModelFields = { | ||
"description": Field(title="some name"), # pass native Pydantic field details | ||
} | ||
|
||
# Using already defined schemas in relations | ||
|
||
list_fields: ModelFields = { | ||
"id": Infer, | ||
"name": Infer, | ||
"description": Infer, | ||
"organization": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
"applications": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
"account": { | ||
"id": Infer, | ||
"name": Infer | ||
}, | ||
} | ||
|
||
|
||
``` | ||
[See usage example here.](examples.ipynb) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.