finish fields docs intial ver,add test for related name, fix child_name(s) in reverse relations
This commit is contained in:
36
docs_src/fields/docs002.py
Normal file
36
docs_src/fields/docs002.py
Normal file
@ -0,0 +1,36 @@
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
import orm
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Department(orm.Model):
|
||||
__database__ = database
|
||||
__metadata__ = metadata
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
|
||||
|
||||
class Course(orm.Model):
|
||||
__database__ = database
|
||||
__metadata__ = metadata
|
||||
|
||||
id = orm.Integer(primary_key=True)
|
||||
name = orm.String(length=100)
|
||||
completed = orm.Boolean(default=False)
|
||||
department = orm.ForeignKey(Department, related_name="my_courses")
|
||||
|
||||
department = Department(name='Science')
|
||||
course = Course(name='Math', completed=False, department=department)
|
||||
|
||||
print(department.my_courses[0])
|
||||
# Will produce:
|
||||
# Course(id=None,
|
||||
# name='Math',
|
||||
# completed=False,
|
||||
# department=Department(id=None, name='Science'))
|
||||
|
||||
Reference in New Issue
Block a user