Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions djantic/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from __future__ import annotations

import inspect
import sys
from enum import Enum
from functools import reduce
from itertools import chain
from typing import Any, Dict, List, Optional, TypeVar, Union, no_type_check
from typing import (
Any,
Dict,
List,
Literal,
Optional,
TypeVar,
Union,
no_type_check,
overload,
)

from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Manager, Model
Expand All @@ -21,7 +33,6 @@
else:
from typing import Union as UnionType


from django.db.models import Model as DjangoModel

from .fields import ModelSchemaField
Expand Down Expand Up @@ -321,6 +332,16 @@ def from_orm(cls, *args, **kwargs):
"""Considered deprecated, use from django instead"""
return cls.from_django(*args, **kwargs)

@classmethod
@overload
def from_django(cls, objs, many: Literal[False] = False, context={}) -> ModelSchema: ...

@classmethod
@overload
def from_django(
cls, objs, many: Literal[True], context={}
) -> List[ModelSchema]: ...

@classmethod
def from_django(cls, objs, many=False, context={}):
if many:
Expand Down