update docs, cleaning
This commit is contained in:
@ -18,5 +18,6 @@ class Course(ormar.Model):
|
||||
|
||||
|
||||
course = Course(name="Painting for dummies", completed=False)
|
||||
await course.save() # type: ignore
|
||||
await Course.objects.create(name="Painting for dummies", completed=False) # type: ignore
|
||||
await course.save()
|
||||
|
||||
await Course.objects.create(name="Painting for dummies", completed=False)
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
from typing import Optional, Union, List
|
||||
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
@ -27,6 +25,4 @@ class Artist(ormar.Model):
|
||||
first_name: str = ormar.String(name="fname", max_length=100)
|
||||
last_name: str = ormar.String(name="lname", max_length=100)
|
||||
born_year: int = ormar.Integer(name="year")
|
||||
children: Optional[Union[Child, List[Child]]] = ormar.ManyToMany(
|
||||
Child, through=ArtistChildren
|
||||
)
|
||||
children = ormar.ManyToMany(Child, through=ArtistChildren)
|
||||
|
||||
19
docs_src/models/docs011.py
Normal file
19
docs_src/models/docs011.py
Normal file
@ -0,0 +1,19 @@
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Course(ormar.Model):
|
||||
class Meta:
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
completed: ormar.Boolean(default=False)
|
||||
|
||||
c1 = Course()
|
||||
17
docs_src/models/docs012.py
Normal file
17
docs_src/models/docs012.py
Normal file
@ -0,0 +1,17 @@
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
|
||||
database = databases.Database("sqlite:///db.sqlite")
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
class Course(ormar.Model):
|
||||
class Meta:
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
completed = ormar.Boolean(default=False)
|
||||
38
docs_src/models/docs013.py
Normal file
38
docs_src/models/docs013.py
Normal file
@ -0,0 +1,38 @@
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
|
||||
database = databases.Database("sqlite:///test.db", force_rollback=True)
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
# note that you do not have to subclass ModelMeta,
|
||||
# it's useful for type hints and code completion
|
||||
class MainMeta(ormar.ModelMeta):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
|
||||
class Artist(ormar.Model):
|
||||
class Meta(MainMeta):
|
||||
# note that tablename is optional
|
||||
# if not provided ormar will user class.__name__.lower()+'s'
|
||||
# -> artists in this example
|
||||
pass
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
first_name: str = ormar.String(max_length=100)
|
||||
last_name: str = ormar.String(max_length=100)
|
||||
born_year: int = ormar.Integer(name="year")
|
||||
|
||||
|
||||
class Album(ormar.Model):
|
||||
class Meta(MainMeta):
|
||||
pass
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
artist: Optional[Artist] = ormar.ForeignKey(Artist)
|
||||
Reference in New Issue
Block a user