class DateFieldsModelNoSubclass(ormar.Model): class Meta: tablename = "test_date_models" metadata = metadata database = db date_id: int = ormar.Integer(primary_key=True) created_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now) updated_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now)
class DateFieldsModel(ormar.Model): class Meta: abstract = True metadata = metadata database = db constraints = [ ormar.UniqueColumns("creation_date", "modification_date") ] created_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now, name="creation_date") updated_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now, name="modification_date")
class Album(ormar.Model): class Meta: tablename = "albums" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=100) timestamp: datetime.datetime = ormar.DateTime(pydantic_only=True) @property_field def name10(self) -> str: return self.name + "_10" @property_field def name20(self) -> str: return self.name + "_20" @property def name30(self) -> str: return self.name + "_30" @property_field def name40(self) -> str: return self.name + "_40"
class Author(ormar.Model): class Meta(BaseMeta): tablename = "authors" id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=100, **default_fernet) uuid_test = ormar.UUID(default=uuid.uuid4, uuid_format="string") uuid_test2 = ormar.UUID(nullable=True, uuid_format="string") password: str = ormar.String( max_length=128, encrypt_secret="udxc32", encrypt_backend=ormar.EncryptBackends.HASH, ) birth_year: int = ormar.Integer( nullable=True, encrypt_secret="secure89key%^&psdijfipew", encrypt_backend=ormar.EncryptBackends.FERNET, ) test_text: str = ormar.Text(default="", **default_fernet) test_bool: bool = ormar.Boolean(nullable=False, **default_fernet) test_float: float = ormar.Float(**default_fernet) test_float2: float = ormar.Float(nullable=True, **default_fernet) test_datetime = ormar.DateTime(default=datetime.datetime.now, **default_fernet) test_date = ormar.Date(default=datetime.date.today, **default_fernet) test_time = ormar.Time(default=datetime.time, **default_fernet) test_json = ormar.JSON(default={}, **default_fernet) test_bigint: int = ormar.BigInteger(default=0, **default_fernet) test_decimal = ormar.Decimal(scale=2, precision=10, **default_fernet) test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2, **default_fernet) custom_backend: str = ormar.String( max_length=200, encrypt_secret="asda8", encrypt_backend=ormar.EncryptBackends.CUSTOM, encrypt_custom_backend=DummyBackend, )
class Organisation(ormar.Model): class Meta: tablename = "org" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) ident: str = ormar.String(max_length=100, choices=["ACME Ltd", "Other ltd"]) priority: int = ormar.Integer(choices=[1, 2, 3, 4, 5]) priority2: int = ormar.BigInteger(choices=[1, 2, 3, 4, 5]) expire_date: datetime.date = ormar.Date( choices=[datetime.date(2021, 1, 1), datetime.date(2022, 5, 1)]) expire_time: datetime.time = ormar.Time( choices=[datetime.time(10, 0, 0), datetime.time(12, 30)]) expire_datetime: datetime.datetime = ormar.DateTime(choices=[ datetime.datetime(2021, 1, 1, 10, 0, 0), datetime.datetime(2022, 5, 1, 12, 30), ]) random_val: float = ormar.Float(choices=[2.0, 3.5]) random_decimal: decimal.Decimal = ormar.Decimal( scale=2, precision=4, choices=[decimal.Decimal(12.4), decimal.Decimal(58.2)]) random_json: pydantic.Json = ormar.JSON(choices=["aa", '{"aa":"bb"}']) random_uuid: uuid.UUID = ormar.UUID(choices=[uuid1, uuid2]) enum_string: str = ormar.String(max_length=100, choices=list(EnumTest))
class Weather(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) temperature: float = ormar.Float() icon: str = ormar.String(max_length=150) pub_date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now)
class Partners(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=50) file: str = ormar.String(max_length=1000) pub_date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now)
class RedefinedField(ormar.Model, DateFieldsMixins): class Meta(ormar.ModelMeta): tablename = "redefined" metadata = metadata database = db id: int = ormar.Integer(primary_key=True) created_date: datetime.datetime = ormar.DateTime(name="creation_date")
class Messages(ormar.Model): class Meta(BaseMeta): tablename = 'messages' id: int = ormar.Integer(primary_key=True, unique=True, nullable=False) user_id: int = ormar.Integer(nullable=False) chat_id: int = ormar.Integer(nullable=False) message_text: str = ormar.Text(nullable=False) date: str = ormar.DateTime(nullable=False)
class Projects(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=150) description: str = ormar.String(max_length=100) file: str = ormar.String(max_length=1000) date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now())
class ResponseMessage(ormar.Model): class Meta(BaseMeta): tablename = "response_messages" id: int = ormar.Integer(primary_key=True) secondary_id: str = ormar.String(max_length=100) username: str = ormar.String(max_length=100) created: datetime = ormar.DateTime() body: str = ormar.String(max_length=1024)
class News(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) title: str = ormar.String(max_length=170) description: str = ormar.String(max_length=500) file: str = ormar.String(max_length=1000, nullable=True) pub_date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now) category: Optional[Category] = ormar.ForeignKey(Category)
class Video(ormar.Model): class Meta(MainMeta): 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 = ormar.DateTime(default=datetime.now) user: Optional[Union[User, Dict]] = ormar.ForeignKey(User)
class Token(ormar.Model): class Meta: tablename = "token" metadata = metadata database = db id = ormar.Integer(primary_key=True) text = ormar.String(max_length=4, unique=True) user = ormar.ForeignKey(User, related_name="tokens") created_at = ormar.DateTime(server_default=sqlalchemy.func.now())
class Report(ormar.Model): class Meta(ormar.ModelMeta): tablename = "reports" database = database metadata = metadata report_id = ormar.Integer(primary_key=True, autoincrement=True) name = ormar.String(max_length=200, unique=True, index=True) filters_position = ormar.String(max_length=200) created_date = ormar.DateTime(server_default=func.now())
class Grants(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) title: str = ormar.String(max_length=150) date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now) pers_name: str = ormar.String(max_length=300) what: str = ormar.String(max_length=1000) description: str = ormar.String(max_length=100) file: str = ormar.String(max_length=1000)
class Event(ormar.Model): class Meta(BaseMeta): tablename = "events" constraints = [ormar.UniqueColumns('code')] id: str = ormar.String(primary_key=True, max_length=100) name: str = ormar.String(max_length=256) description: Optional[str] = ormar.String(max_length=256, default="") code: str = ormar.String(max_length=256) start_date: datetime = ormar.DateTime() expiry_date: datetime = ormar.DateTime() minimum_karma: int = ormar.Integer(default=0) minimum_age: int = ormar.Integer(default=0) def expired(self): return self.expiry_date < datetime.utcnow() def started(self): return self.start_date < datetime.utcnow()
class Product(ormar.Model): class Meta: tablename = "product" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=100) company: str = ormar.String(max_length=200, server_default="Acme") sort_order: int = ormar.Integer(server_default=text("10")) created: datetime = ormar.DateTime(server_default=func.now())
class Contact(ormar.Model): class Meta(MainMeta): pass id: int = ormar.Integer(primary_key=True) title: str = ormar.String(max_length=150) face: str = ormar.String(max_length=150) phone: str = ormar.String(max_length=15) date: datetime.datetime = ormar.DateTime(default=datetime.datetime.now()) email: str = ormar.String(max_length=100) message: str = ormar.String(max_length=100) checked: bool = ormar.Boolean(default=False)
class Car(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) co_owner: Person = ormar.ForeignKey(Person, related_name="coowned") created_date: datetime.datetime = ormar.DateTime( default=datetime.datetime.now)
class Example(ormar.Model): class Meta: tablename = "example" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) name: str = ormar.String(max_length=200, default="aaa") created: datetime.datetime = ormar.DateTime(default=datetime.datetime.now) created_day: datetime.date = ormar.Date(default=datetime.date.today) created_time: datetime.time = ormar.Time(default=time) description: str = ormar.Text(nullable=True) value: float = ormar.Float(nullable=True) data: pydantic.Json = ormar.JSON(default={})
class OrmarBaseOAuthAccountModel(ormar.Model): class Meta: tablename = "oauth_accounts" abstract = True id = ormar.UUID(primary_key=True, uuid_format="string") oauth_name = ormar.String(nullable=False, max_length=255) access_token = ormar.String(nullable=False, max_length=255) expires_at = ormar.Integer(nullable=True) refresh_token = ormar.String(nullable=True, max_length=255) account_id = ormar.String(index=True, nullable=False, max_length=255) account_email = ormar.String(nullable=False, max_length=255) # added to keep ordering by creation_date created_date = ormar.DateTime(default=datetime.datetime.now)
class User2(ormar.Model): class Meta: tablename: str = "users2" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) email: str = ormar.String(max_length=255, nullable=False) password: str = ormar.String(max_length=255) first_name: str = ormar.String(max_length=255) last_name: str = ormar.String(max_length=255) category: str = ormar.String(max_length=255, nullable=True) timestamp: datetime.datetime = ormar.DateTime( pydantic_only=True, default=datetime.datetime.now)
class Chart(ormar.Model): class Meta(ormar.ModelMeta): tablename = "charts" database = database metadata = metadata chart_id = ormar.Integer(primary_key=True, autoincrement=True) name = ormar.String(max_length=200, unique=True, index=True) query_text = ormar.Text() datasets = ormar.JSON() layout = ormar.JSON() data_config = ormar.JSON() created_date = ormar.DateTime(server_default=func.now()) library = ormar.String(max_length=200, default="plotly") used_filters = ormar.JSON()
class Filter(ormar.Model): class Meta(ormar.ModelMeta): tablename = "filters" database = database metadata = metadata filter_id = ormar.Integer(primary_key=True, autoincrement=True) name = ormar.String(max_length=200, unique=True, index=True) label = ormar.String(max_length=200) query_text = ormar.Text() allow_multiselect = ormar.Boolean(default=True) created_date = ormar.DateTime(server_default=func.now()) is_dynamic = ormar.Boolean(default=True) is_date = ormar.Boolean(default=False) translation = ormar.ForeignKey(TranslationNode, name="translation_node_id")
class RandomModel(ormar.Model): class Meta: tablename: str = "random_users" metadata = metadata database = database id: int = ormar.Integer(primary_key=True) password: str = ormar.String(max_length=255, default=gen_pass) first_name: str = ormar.String(max_length=255, default="John") last_name: str = ormar.String(max_length=255) created_date: datetime.datetime = ormar.DateTime( server_default=sqlalchemy.func.now()) @property_field def full_name(self) -> str: return " ".join([self.first_name, self.last_name])
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 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 ExampleModel(Model): class Meta: tablename = "example" metadata = metadata test: int = ormar.Integer(primary_key=True) test_string: str = ormar.String(max_length=250) test_text: str = ormar.Text(default="") test_bool: bool = ormar.Boolean(nullable=False) test_float: ormar.Float() = None # type: ignore test_datetime = ormar.DateTime(default=datetime.datetime.now) test_date = ormar.Date(default=datetime.date.today) test_time = ormar.Time(default=datetime.time) test_json = ormar.JSON(default={}) test_bigint: int = ormar.BigInteger(default=0) test_decimal = ormar.Decimal(scale=2, precision=10) test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2)
class PlayedTrack(ormar.Model): """ `played_tracks` table mapping. Attributes ---------- id: str, primary key user: User, foreign key track: Track, foreign key played_at: datetime """ class Meta(BaseMeta): pass id: int = ormar.Integer(primary_key=True, autoincrement=True) user: User = ormar.ForeignKey(User) track: Track = ormar.ForeignKey(Track) played_at: datetime = ormar.DateTime()