class Post(BaseDBModel): title = CharField(max_length=255, null=False) slug = CharField(unique=True, max_length=63, null=False) content = TextField(default='') metadata = JSONField(default=dict) author = ForeignKeyField(Author, null=True) tags = ManyToManyField(Tag, 'PostTags') @classmethod @depends_on(metadata) async def fields_list(cls): for key in cls.fields().keys(): yield key @property @depends_on(slug) def urlpath(self): return f'/{self.slug}/' @depends_on(slug) def url(self): return f'http://example.com/{self.slug}/' # Just to test async methods serialization @depends_on(author) async def status(self): return 'OK'
class Log(BaseDBModel): action_type = CharField(max_length=63, null=False) obj_id = SmallIntegerField(null=False) state_before = JSONField(default=dict, null=True) state_after = JSONField(default=dict, null=True) class ActionType(Enum): CREATE = 'create' UPDATE = 'update' DESTROY = 'destroy'
class Tag(BaseDBModel): name = CharField(max_length=127, null=False) slug = CharField(max_length=127, null=False, unique=True)
class Author(BaseDBModel): first_name = CharField(max_length=127, null=False) last_name = CharField(max_length=127, null=True) nickname = CharField(max_length=127, null=False, unique=True)