field_generator.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import tortoise.fields
  2. from .constants import constants
  3. class field_generator:
  4. @staticmethod
  5. def id() -> tortoise.fields.IntField:
  6. return tortoise.fields.IntField(primary_key = True)
  7. @staticmethod
  8. def name() -> tortoise.fields.TextField:
  9. return tortoise.fields.TextField(max_lenght = 30)
  10. @staticmethod
  11. def password() -> tortoise.fields.TextField:
  12. return tortoise.fields.TextField(max_lenght = 256)
  13. @staticmethod
  14. def surname() -> tortoise.fields.TextField:
  15. return tortoise.fields.TextField(max_lenght = 30)
  16. @staticmethod
  17. def nick() -> tortoise.fields.TextField:
  18. return tortoise.fields.TextField(max_lenght = 20)
  19. @staticmethod
  20. def description() -> tortoise.fields.TextField:
  21. return tortoise.fields.TextField(max_lenght = 4096)
  22. @staticmethod
  23. def phone_number() -> tortoise.fields.TextField:
  24. return tortoise.fields.TextField(max_lenght = 15)
  25. @staticmethod
  26. def barcode() -> tortoise.fields.TextField:
  27. return tortoise.fields.TextField(max_lenght = 13)
  28. @staticmethod
  29. def email() -> tortoise.fields.TextField:
  30. return tortoise.fields.TextField(max_lenght = 30)
  31. @staticmethod
  32. def apikey() -> tortoise.fields.TextField:
  33. return tortoise.fields.TextField(max_lenght = 280)
  34. @staticmethod
  35. def secret() -> tortoise.fields.TextField:
  36. return tortoise.fields.TextField(max_lenght = 256)
  37. @staticmethod
  38. def permissions() -> tortoise.fields.BooleanField:
  39. return tortoise.fields.BooleanField()
  40. @staticmethod
  41. def stock() -> tortoise.fields.IntField:
  42. return tortoise.fields.IntField
  43. @staticmethod
  44. def boolean() -> tortoise.fields.BooleanField:
  45. return tortoise.fields.BooleanField()
  46. @staticmethod
  47. def __connected_names(
  48. target: type,
  49. own: type | str,
  50. field: str | None) -> [str, str]:
  51. target_model = constants.get_model_name(target)
  52. related_field = constants.get_related_name(own, field)
  53. return target_model, related_field
  54. @classmethod
  55. def connected_many(
  56. cls,
  57. target: type,
  58. own: type | str,
  59. field: str | None = None
  60. ) -> tortoise.fields.ManyToManyField:
  61. model, related = cls.__connected_names(target, own, field)
  62. return tortoise.fields.ManyToManyField(
  63. model,
  64. related_name = related
  65. )
  66. @classmethod
  67. def connected_single(
  68. cls,
  69. target: type,
  70. own: type | str,
  71. field: str | None = None
  72. ) -> tortoise.fields.ForeignKeyField:
  73. model, related = cls.__connected_names(target, own, field)
  74. return tortoise.fields.ForeignKeyField(
  75. model,
  76. related_name = related
  77. )