work on relations docs
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 orm
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Album(orm.Model):
|
||||
__tablename__ = "album"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
|
||||
|
||||
class Track(orm.Model):
|
||||
__tablename__ = "track"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
album = orm.ForeignKey(Album)
|
||||
title = orm.String(length=100)
|
||||
position = orm.Integer()
|
||||
39
docs_src/relations/docs002.py
Normal file
39
docs_src/relations/docs002.py
Normal file
@ -0,0 +1,39 @@
|
||||
import orm
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Album(orm.Model):
|
||||
__tablename__ = "album"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
|
||||
|
||||
class Track(orm.Model):
|
||||
__tablename__ = "track"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
album = orm.ForeignKey(Album)
|
||||
title = orm.String(length=100)
|
||||
position = orm.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 orm
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class SchoolClass(orm.Model):
|
||||
__tablename__ = "schoolclasses"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
|
||||
|
||||
class Category(orm.Model):
|
||||
__tablename__ = "categories"
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
|
||||
|
||||
class Student(orm.Model):
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
schoolclass = orm.ForeignKey(SchoolClass)
|
||||
category = orm.ForeignKey(Category)
|
||||
|
||||
|
||||
class Teacher(orm.Model):
|
||||
__metadata__ = metadata
|
||||
__database__ = database
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
schoolclass = orm.ForeignKey(SchoolClass)
|
||||
category = orm.ForeignKey(Category)
|
||||
Reference in New Issue
Block a user