A utility that allows you to convert ORM models.
Project description
Orm-Converter
Installation
pip install orm-converter
or
pip install git+https://github.com/MaxZayats/orm-converter
Available conversions
TortoiseORM
->DjangoORM
Usage Examples
1. Simple Usage
from orm_converter.tortoise_to_django import ConvertedModel
from tortoise import fields
from tortoise.models import Model as TortoiseModel
class ExampleModel(TortoiseModel, ConvertedModel):
example_field = fields.IntField()
ExampleModel.DjangoModel # <- Converted Django Model
2. Redefining fields/attributes
from orm_converter.tortoise_to_django import (ConvertedModel,
RedefinedAttributes)
from tortoise.models import Model as TortoiseModel
from custom_django_fields import CustomDjangoField
from custom_tortoise_fields import CustomTortoiseField
class ExampleModel(TortoiseModel, ConvertedModel):
custom_field = CustomTortoiseField()
class RedefinedAttributes(RedefinedAttributes):
"""
In this class you can redefine your tortoise attributes to django attributes.
You can use this if you have a custom fields
Or if `orm_converter` converts fields incorrectly.
"""
custom_field = CustomDjangoField()
3. Adding custom converters
from orm_converter.tortoise_to_django import (BaseTortoiseFieldConverter,
ConvertedModel, Converter)
from tortoise.models import Model as TortoiseModel
from custom_django_fields import CustomDjangoField
from custom_tortoise_fields import CustomTortoiseField
class MyCustomFieldConverter(BaseTortoiseFieldConverter):
ORIGINAL_FIELD_TYPE = CustomTortoiseField
CONVERTED_FIELD_TYPE = CustomDjangoField
def _reformat_kwargs(self):
super()._reformat_kwargs()
# change field kwargs here
self._original_field_kwargs["custom_kwarg"] = "Django"
Converter.add_converters(MyCustomFieldConverter)
class ExampleModel(TortoiseModel, ConvertedModel):
custom_field = CustomTortoiseField(custom_kwarg="Tortoise")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
orm_converter-0.2.1b1.tar.gz
(6.7 kB
view hashes)
Built Distribution
Close
Hashes for orm_converter-0.2.1b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a033841a400ba5df093ddf7c9d2d9692073d33026636d09ad13346d652abc47 |
|
MD5 | 1dc8744b1d253ccec787e2e5feea7e54 |
|
BLAKE2b-256 | 438111013b9e5c6c8d20b5c120048dbcfc5f56c5469218917d59aaea81e20bbb |