class ItemModel(BaseSQLModel): id = AutoField() title = CharField(max_length=64) user = ForeignKeyField(UserModel, backref="items", on_delete="CASCADE") category = ForeignKeyField(CategoryModel, backref="items", on_delete="CASCADE") brand = ForeignKeyField(BrandModel, backref="items", on_delete="CASCADE") tags = ManyToManyField(TagModel, backref="items") condition = CharField(choices=ItemCondition) value = DecimalField(decimal_places=2, auto_round=True) currency = CharField(choices=Currency) description = CharField(max_length=128) status = CharField(choices=ItemStatus, default=ItemStatus.AVAILABLE) preference_score_rate = DecimalField(decimal_places=2, auto_round=True, default=0) popularity_rate = DecimalField(decimal_places=2, auto_round=True, default=0) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "items" def __str__(self): return self.name
class Workout(BaseModel): id = PrimaryKeyField() name = CharField(null=False) category = CharField() start_time = DateTimeField(default=datetime.now()) end_time = DateTimeField(null=True) creator = CharField(null=False) exercises = JSONField(default=[])
class Post(BaseModel): id = PrimaryKeyField() comments = JSONField(default=[]) photo = CharField(null=True) caption = CharField(null=True) date = DateTimeField(default=datetime.now()) original_workout = ForeignKeyField(Workout) class Meta: index = ('post', 'original_workout')
class CardModel(BaseSQLModel): id = AutoField() author = ForeignKeyField(UserModel, backref="cards", on_delete="CASCADE") list = ForeignKeyField(ListModel, backref="cards", on_delete="CASCADE") title = CharField(max_length=256) description = CharField(max_length=1024) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "cards"
class UserModel(BaseSQLModel, UserMixin): id = AutoField() username = CharField(unique=True, index=True, max_length=16) email_address = CharField(unique=True, max_length=256) salt = BlobField() key = BlobField() role = CharField(default=UserRole.MEMBER) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "users"
class Article(BaseModel): title = CharField(unique=True, verbose_name="title") content = TextField(verbose_name="content") tag = ForeignKeyField(Tag, related_name="articles", verbose_name="tag") create_time = DateTimeField(default=datetime.now, verbose_name="create time") up_time = DateTimeField(default=datetime.now, verbose_name="create time")
class Machine(Model): name = CharField(index=True, unique=True) metadata = BinaryJSONField() train_start_date = DateTimeTZField() train_end_date = DateTimeTZField() class Meta: database = db @classmethod def from_endpoint(cls, ep): """ Returns a Machine object constructed from a valid endpoint. Parameters ---------- ep: Dict Endpoint from watchman Returns ------- Machine """ return cls(**endpoint_to_machine_data(ep)) def __repr__(self): return f"Machine {self.__data__} "
class Game(BaseModel): """Game model.""" title = CharField( max_length=100, unique=True, ) config = JSONField()
class WordEmbedding(BaseModel): word = CharField(null=False) embedding = BinaryJSONField(null=False) version = IntegerField(null=False) inserted_at = DateTimeField(null=False, default=datetime.now) class Meta: db_table = 'word_embeddings'
class ListModel(BaseSQLModel): id = AutoField() # TODO: Restrict author must be role ADMIN author = ForeignKeyField(UserModel, backref="lists", on_delete="CASCADE") title = CharField(max_length=256) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "lists"
class CommentReplyModel(BaseSQLModel): id = AutoField() author = ForeignKeyField(UserModel, backref="replies", on_delete="CASCADE") comment = ForeignKeyField(CommentModel, backref="replies", on_delete="CASCADE") content = CharField(max_length=256) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) class Meta(BaseSQLModel): table_name = "comment_replies"
class ImageModel(BaseSQLModel): id = AutoField() url = CharField(max_length=256) item = ForeignKeyField(ItemModel, backref="images", on_delete="CASCADE") date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "images" def __str__(self): return self.url
class Machine(Model): name = CharField(index=True, unique=True) dataset = BinaryJSONField() model = BinaryJSONField() metadata = BinaryJSONField() class Meta: primary_key = False database = db table_name = "machine" def __repr__(self): return f"Machine {self.__data__} "
class CommentModel(BaseSQLModel): id = AutoField() author = ForeignKeyField(UserModel, backref="comments", on_delete="CASCADE") card = ForeignKeyField(CardModel, backref="comments", on_delete="CASCADE") content = CharField(max_length=256) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "comments"
class User(BaseModel): login = CharField(unique=True) email = CharField(unique=True) pw_hash = TextField() authenticated = BooleanField(default=False) active = BooleanField(default=False) def is_authenticated(self): return self.authenticated def is_active(self): return self.active def is_anonymous(self): return False def get_id(self): return self.login def set_password(self, password): self.pw_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.pw_hash, password)
class CategoryModel(BaseSQLModel): id = AutoField() name = CharField(unique=True, max_length=64) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "categories" def __str__(self): return self.name def save(self, *args, **kwargs): self.name = self.name.lower() return super().save(*args, **kwargs)
class TagModel(BaseSQLModel): id = AutoField() value = CharField(unique=True, max_length=64) date_created = DateTimeField(null=True) date_updated = DateTimeField(null=True) is_deleted = BooleanField(default=False) class Meta(BaseSQLModel): table_name = "tags" def __str__(self): return self.value def get(self, **kwargs): kwargs["value"] = kwargs["value"].lower() return super().get(**kwargs) def save(self, *args, **kwargs): self.value = self.value.lower() return super().save(*args, **kwargs)
class Sale(BaseModel): id = IntegerField(primary_key=True) city = CharField(null=True) district = CharField(null=True) address = CharField(null=True) latitude = FloatField(null=True) longitude = FloatField(null=True) floor = IntegerField(null=True) number_of_floors = IntegerField(null=True) number_of_rooms = IntegerField(null=True) kitchen_area = FloatField(null=True) living_area = FloatField(null=True) total_area = FloatField(null=True) walling = CharField(null=True) price_amount = FloatField(null=True) price_currency = CharField(null=True) seller = CharField(null=True) resale = BooleanField(null=True) image = CharField(null=True) url = CharField(null=True) created_at = DateTimeField(default=datetime.utcnow) updated_at = DateTimeField(default=datetime.utcnow)
class Team(BaseModel): name = CharField(null=False, unique=True, primary_key=True)
class Chat(BaseModel): id = PrimaryKeyField() events = JSONField(default=[]) name = CharField() date_created = DateTimeField(default=datetime.now) background = CharField(default="default")
class AuthId(BaseModel): auth_id = CharField(unique=True, null=False) user = ForeignKeyField(User) date_created = DateTimeField(default=datetime.now)
class MigrationHistory(BaseModel): migration = CharField() applied_at = DateTimeField(default=datetime.utcnow)
class User(BaseModel): name = CharField(unique=True, primary_key=True) photo = CharField(null=True)
class Tag(BaseModel): name = CharField(unique=True, verbose_name="name") desc = CharField(verbose_name="description")