tortoise / tortoise/tortoise-orm
How to exclude fields of nested objects that are in m2m relation when creating PydanticModel using pydantic_model_creator?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Assuming following setup:
class Recipe(Model):
...
ingredients = fields.ManyToManyField(model_name="models.Ingredient", related_name="recipes", null=True,
on_delete=fields.SET_NULL,
description="List of required ingredients")
class Ingredient(Model):
name: fields.CharField()
not_needed: fields.CharField()
I want to create a PydanticModel for Recipe that won't contain Ingredient.not_needed field, like so:
pydantic_model_creator(Recipe, exclude=("ingredients.not_needed"))
One thing that comes to my mind is to use computed property but are there any other approaches to this problem?
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 by reading pydantic_model_creator and the nested relation handling it uses. Check whether exclusions are supported across ManyToMany fields and whether existing tests cover nested model fields. Done means establishing and documenting a supported way to omit Ingredient.not_needed, or clearly scoping the required feature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100