version with pydantic inheritance passing all the tests
This commit is contained in:
26
docs_src/relations/docs001.py
Normal file
26
docs_src/relations/docs001.py
Normal file
@ -0,0 +1,26 @@
|
||||
import ormar
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Album(ormar.Model):
|
||||
__tablename__ = "album"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
|
||||
|
||||
class Track(ormar.Model):
|
||||
__tablename__ = "track"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
album = ormar.ForeignKey(Album)
|
||||
title = ormar.String(length=100)
|
||||
position = ormar.Integer()
|
||||
39
docs_src/relations/docs002.py
Normal file
39
docs_src/relations/docs002.py
Normal file
@ -0,0 +1,39 @@
|
||||
import ormar
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Album(ormar.Model):
|
||||
__tablename__ = "album"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
|
||||
|
||||
class Track(ormar.Model):
|
||||
__tablename__ = "track"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
album = ormar.ForeignKey(Album)
|
||||
title = ormar.String(length=100)
|
||||
position = ormar.Integer()
|
||||
|
||||
|
||||
print(Track.__table__.columns['album'].__repr__())
|
||||
# Will produce:
|
||||
# Column('album', Integer(), ForeignKey('album.id'), table=<track>)
|
||||
|
||||
print(Track.__pydantic_model__.__fields__['album'])
|
||||
# Will produce:
|
||||
# ModelField(
|
||||
# name='album'
|
||||
# type=Optional[Album]
|
||||
# required=False
|
||||
# default=None)
|
||||
44
docs_src/relations/docs003.py
Normal file
44
docs_src/relations/docs003.py
Normal file
@ -0,0 +1,44 @@
|
||||
import databases
|
||||
import sqlalchemy
|
||||
import ormar
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class SchoolClass(ormar.Model):
|
||||
__tablename__ = "schoolclasses"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
__tablename__ = "categories"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
|
||||
|
||||
class Student(ormar.Model):
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
schoolclass = ormar.ForeignKey(SchoolClass)
|
||||
category = ormar.ForeignKey(Category)
|
||||
|
||||
|
||||
class Teacher(ormar.Model):
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(length=100)
|
||||
schoolclass = ormar.ForeignKey(SchoolClass)
|
||||
category = ormar.ForeignKey(Category)
|
||||
Reference in New Issue
Block a user