class Artist(ormar.Model): class Meta: tablename = "artists" metadata = metadata database = database id: int = ormar.Integer(name="artist_id", primary_key=True) 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[List[Child]] = ormar.ManyToMany(Child)
class Post(ormar.Model): class Meta: tablename = "posts" database = database metadata = metadata 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)
class Student(ormar.Model): class Meta: database = database metadata = metadata id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=100) courses = ormar.ManyToMany( Course, through_relation_name="student_id", through_reverse_relation_name="course_id", )
class Human(ormar.Model): class Meta(BaseMeta): tablename = "humans" id: UUID = ormar.UUID(primary_key=True, default=uuid4) name: str = ormar.Text(default="") pets: List[Animal] = ormar.ManyToMany( Animal, related_name="care_takers", orders_by=["specie", "-name"], related_orders_by=["name"], )
class PrimaryModel(ormar.Model): class Meta: metadata = metadata database = db tablename = "primary_models" id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=255, index=True) some_text: str = ormar.Text() some_other_text: Optional[str] = ormar.Text(nullable=True) keywords: Optional[List[Keyword]] = ormar.ManyToMany( Keyword, through=KeywordPrimaryModel)
class Human(ormar.Model): class Meta(BaseMeta): tablename = "humans" id: UUID = ormar.UUID(primary_key=True, default=uuid4) name: str = ormar.Text(default="") favoriteAnimals: List[Animal] = ormar.ManyToMany( Animal, through=Link, related_name="favoriteHumans", orders_by=["link__animal_order"], related_orders_by=["link__human_order"], )
class Car2(ormar.Model): class Meta: abstract = True metadata = metadata database = db id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=50) owner: Person = ormar.ForeignKey(Person, related_name="owned") co_owners: List[Person] = ormar.ManyToMany(Person, through=PersonsCar, related_name="coowned") created_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now)
class Child(ormar.Model): class Meta(ModelMeta): metadata = metadata database = db id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=100) favourite_game: GameRef = ormar.ForeignKey(GameRef, related_name="liked_by") least_favourite_game: GameRef = ormar.ForeignKey( GameRef, related_name="not_liked_by") friends = ormar.ManyToMany(ChildRef, through=ChildFriendRef, related_name="also_friends")
class Video(ormar.Model): class Meta(MainMata): pass id: int = ormar.Integer(primary_key=True) title: str = ormar.String(max_length=50) description: str = ormar.String(max_length=500) file: str = ormar.String(max_length=1000) create_at: datetime.datetime = ormar.DateTime( default=datetime.datetime.now) user: Optional[Union[User, Dict]] = ormar.ForeignKey(User, related_name="user_video") like_count: int = ormar.Integer(default=0) like_user: Optional[Union[List[User], Dict]] = ormar.ManyToMany( User, related_name="like_users", through=UserLike)
class User(ormar.Model): class Meta(MainMeta): pass registrationnumber: str = ormar.String(primary_key=True, max_length=1000) company: Company = ormar.ForeignKey(Company) company2: Company = ormar.ForeignKey(Company, related_name="secondary_users") name: str = ormar.Text() role: Optional[Role] = ormar.ForeignKey(Role) roleforcompanies: Optional[Union[Company, List[Company]]] = ormar.ManyToMany( Company, through=UserRoleCompany, related_name="role_users") lastupdate: date = ormar.DateTime(server_default=sqlalchemy.func.now())
class Session(ormar.Model): class Meta: metadata = metadata database = db tablename = "test_sessions" id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=255, index=True) some_text: str = ormar.Text() some_other_text: Optional[str] = ormar.Text(nullable=True) teacher: Optional[User] = ormar.ForeignKey(User, nullable=True, related_name="teaching") students: Optional[List[User]] = ormar.ManyToMany(User, through=Signup, related_name="attending")