| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import tortoise.fields
- from .constants import constants
- class field_generator:
- @staticmethod
- def id() -> tortoise.fields.IntField:
- return tortoise.fields.IntField(primary_key = True)
- @staticmethod
- def name() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 30)
- @staticmethod
- def password() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 256)
- @staticmethod
- def surname() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 30)
- @staticmethod
- def nick() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 20)
- @staticmethod
- def description() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 4096)
-
- @staticmethod
- def phone_number() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 15)
- @staticmethod
- def barcode() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 13)
- @staticmethod
- def email() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 30)
- @staticmethod
- def apikey() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 280)
- @staticmethod
- def secret() -> tortoise.fields.TextField:
- return tortoise.fields.TextField(max_lenght = 256)
- @staticmethod
- def permissions() -> tortoise.fields.BooleanField:
- return tortoise.fields.BooleanField()
- @staticmethod
- def stock() -> tortoise.fields.IntField:
- return tortoise.fields.IntField
- @staticmethod
- def boolean() -> tortoise.fields.BooleanField:
- return tortoise.fields.BooleanField()
- @staticmethod
- def __connected_names(
- target: type,
- own: type | str,
- field: str | None) -> [str, str]:
- target_model = constants.get_model_name(target)
- related_field = constants.get_related_name(own, field)
-
- return target_model, related_field
- @classmethod
- def connected_many(
- cls,
- target: type,
- own: type | str,
- field: str | None = None
- ) -> tortoise.fields.ManyToManyField:
- model, related = cls.__connected_names(target, own, field)
- return tortoise.fields.ManyToManyField(
- model,
- related_name = related
- )
- @classmethod
- def connected_single(
- cls,
- target: type,
- own: type | str,
- field: str | None = None
- ) -> tortoise.fields.ForeignKeyField:
- model, related = cls.__connected_names(target, own, field)
- return tortoise.fields.ForeignKeyField(
- model,
- related_name = related
- )
|