restore typing in tests and docs, remove unused metaclass code
This commit is contained in:
0
docs_src/relations/__init__.py
Normal file
0
docs_src/relations/__init__.py
Normal file
@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, Dict, Union
|
||||
|
||||
import databases
|
||||
import sqlalchemy
|
||||
@ -14,8 +14,8 @@ class Department(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Course(ormar.Model):
|
||||
@ -23,22 +23,22 @@ class Course(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
completed= ormar.Boolean(default=False)
|
||||
department= ormar.ForeignKey(Department)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
completed: bool = ormar.Boolean(default=False)
|
||||
department: Optional[Union[Department, Dict]] = ormar.ForeignKey(Department)
|
||||
|
||||
|
||||
department = Department(name='Science')
|
||||
department = Department(name="Science")
|
||||
|
||||
# set up a relation with actual Model instance
|
||||
course = Course(name='Math', completed=False, department=department)
|
||||
course = Course(name="Math", completed=False, department=department)
|
||||
|
||||
# set up relation with only related model pk value
|
||||
course2 = Course(name='Math II', completed=False, department=department.pk)
|
||||
course2 = Course(name="Math II", completed=False, department=department.pk)
|
||||
|
||||
# set up a relation with dictionary corresponding to related model
|
||||
course3 = Course(name='Math III', completed=False, department=department.dict())
|
||||
course3 = Course(name="Math III", completed=False, department=department.dict())
|
||||
|
||||
# explicitly set up None
|
||||
course4 = Course(name='Math III', completed=False, department=None)
|
||||
course4 = Course(name="Math III", completed=False, department=None)
|
||||
|
||||
@ -14,9 +14,9 @@ class Author(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
first_name = ormar.String(max_length=80)
|
||||
last_name = ormar.String(max_length=80)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
first_name: str = ormar.String(max_length=80)
|
||||
last_name: str = ormar.String(max_length=80)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
@ -25,8 +25,8 @@ class Category(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=40)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=40)
|
||||
|
||||
|
||||
class PostCategory(ormar.Model):
|
||||
@ -44,7 +44,9 @@ class Post(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
title = ormar.String(max_length=200)
|
||||
categories: Optional[Union[Category, List[Category]]] = ormar.ManyToMany(Category, through=PostCategory)
|
||||
author= ormar.ForeignKey(Author)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
title: str = ormar.String(max_length=200)
|
||||
categories: Optional[Union[Category, List[Category]]] = ormar.ManyToMany(
|
||||
Category, through=PostCategory
|
||||
)
|
||||
author: Optional[Author] = ormar.ForeignKey(Author)
|
||||
|
||||
Reference in New Issue
Block a user