version with pydantic inheritance passing all the tests

This commit is contained in:
collerek
2020-08-19 18:40:57 +07:00
commit 0b156caf0a
58 changed files with 4853 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import databases
import sqlalchemy
import ormar
database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
class Department(ormar.Model):
__database__ = database
__metadata__ = metadata
id = ormar.Integer(primary_key=True)
name = ormar.String(length=100)
class Course(ormar.Model):
__database__ = database
__metadata__ = metadata
id = ormar.Integer(primary_key=True)
name = ormar.String(length=100)
completed = ormar.Boolean(default=False)
department = ormar.ForeignKey(Department)
department = Department(name='Science')
course = Course(name='Math', completed=False, department=department)
print(department.courses[0])
# Will produce:
# Course(id=None,
# name='Math',
# completed=False,
# department=Department(id=None, name='Science'))