Exemplo n.º 1
0
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'
Exemplo n.º 2
0
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'
Exemplo n.º 3
0
class Tag(BaseDBModel):
    name = CharField(max_length=127, null=False)
    slug = CharField(max_length=127, null=False, unique=True)
Exemplo n.º 4
0
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)