Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

orm-converter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orm-converter

A utility that allows you to convert ORM models.

  • 0.2.2b0
  • PyPI
  • Socket score

Maintainers
1

PyPI version Code style: black Imports: isort Checked with mypy

Orm-Converter

Installation

pip install orm-converter

or

pip install git+https://github.com/MaxZayats/orm-converter

Available conversions

  1. 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")

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc