tortoise / tortoise/tortoise-orm
How to map M2M manually in pydantic class?
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Following setup:
class Person(Model):
...
items = fields.ManyToManyField('models.Item', related_name="people")
class ItemDTO(BaseModel):
...
class PersonDTO(BaseModel):
...
items: list[ItemDTO] #this does not work
class Config:
orm_mode=True
When trying:
PersonDTO.from_orm(await Person.get_or_none(pk=1))
It gives me an error:
items value is not a list
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Person, Item, and DTO definitions and the PersonDTO.from_orm call shown in the issue. Reproduce the “items value is not a list” error with the ManyToMany relation, then determine whether the expected outcome is implementation guidance or a library/documentation change; the report does not define what done looks like.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, database
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100