tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.69k stars 390 forks source link

feat: add mixin for int enum field custom #1781

Open waketzheng opened 4 days ago

waketzheng commented 4 days ago

Description

As #966 said, IntEnumField inherit from SmallIntField, so it can not use a enum_type with value > 32767

Motivation and Context

This PR add a IntEnumFieldMixin to make it easy to custom a new IntEnumField:

from typing import Type, cast
from tortoise.fields.data import IntEnumFieldMixin, IntEnumType, IntField

class IntEnumInstance(IntEnumFieldMixin, IntField):
    pass

def IntEnumField(enum_type: Type[IntEnumType], **kwargs) -> IntEnumType:
    return cast(IntEnumType, IntEnumInstance(enum_type, **kwargs))

How Has This Been Tested?

make ci

Checklist:

coveralls commented 4 days ago

Pull Request Test Coverage Report for Build 11994687751

Details


Totals Coverage Status
Change from base Build 11994314143: -0.002%
Covered Lines: 6234
Relevant Lines: 6856

💛 - Coveralls