tortoise / tortoise/tortoise-orm

CompositeFields

Open
#626 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Hi everyone! First of all, thanks for maintaining such a great ORM! =)
I have a single question: Is there a way have something similar to a CompositeField in Tortoise?

We are migrating from a django project and we have tables we want to keep.
e.g.

class Position(CompositeField):
    x = models.FloatField()
    y = models.FloatField()


class Path(django.models.Model):
   id ...
   origin = Position()
   destination = Position()

and that maps to a table like this one

id | origin_x | origin_y | destination_x | destination_y
--------------------------------------------------------

But in Tortoise CompositeFields does not exist.

my workaround would be to create a model like this

class Path(tortoise.models.Model):
   id ...
   origin_x  = models.FloatField()
   origin_y  = models.FloatField()
   destination_x  = models.FloatField()
   destination_y  = models.FloatField()

to match the previous one in Django, but the issue with that is, our real models contains much much more references between them, with much more fields. So it will intermediately become unmanageable

Additional context
This software is installed in many different productive environments, so I would need to keep the data that we ahve in our sql databases, hence, our schema as it is right now while we deploy to upgrade from django to tortoise.

Thanks in advance, for any clue you can provide about how to implement this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files, tests, or entry points are named. Start by tracing Tortoise's model and field mapping for the shown Path and Position shape, then compare it with the existing Django schema; done means the issue's composite-field requirement is addressed without changing the listed columns.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.