-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from collerek/many_to_many
Many to many
- Loading branch information
Showing
19 changed files
with
880 additions
and
254 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
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
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,40 @@ | ||
from typing import TYPE_CHECKING, Type | ||
|
||
from ormar.fields import BaseField | ||
from ormar.fields.foreign_key import ForeignKeyField | ||
|
||
if TYPE_CHECKING: # pragma no cover | ||
from ormar.models import Model | ||
|
||
|
||
def ManyToMany( | ||
to: Type["Model"], | ||
through: Type["Model"], | ||
*, | ||
name: str = None, | ||
unique: bool = False, | ||
related_name: str = None, | ||
virtual: bool = False, | ||
) -> Type[object]: | ||
to_field = to.__fields__[to.Meta.pkname] | ||
namespace = dict( | ||
to=to, | ||
through=through, | ||
name=name, | ||
nullable=True, | ||
unique=unique, | ||
column_type=to_field.type_.column_type, | ||
related_name=related_name, | ||
virtual=virtual, | ||
primary_key=False, | ||
index=False, | ||
pydantic_only=False, | ||
default=None, | ||
server_default=None, | ||
) | ||
|
||
return type("ManyToMany", (ManyToManyField, BaseField), namespace) | ||
|
||
|
||
class ManyToManyField(ForeignKeyField): | ||
through: Type["Model"] |
Oops, something went wrong.