One sided relations and more powerful save_related #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
0.10.3
✨ Features
ForeignKey
andManyToMany
now supportskip_reverse: bool = False
flag #118.If you set
skip_reverse
flag internally the field is still registered on the otherside of the relationship so you can:
filter
by related models fields from reverse modelorder_by
by related models fields from reverse modelBut you cannot:
related_name
select_related
from reverse side of the model the returned models won't be populated in reversed instance (the join is not prevented so you still canfilter
andorder_by
)dict()
andjson()
dict()
orjson()
(also throughfastapi
). It will be either ignored or raise error depending onextra
setting in pydanticConfig
.Model.save_related()
now can save whole data tree in once #148meaning:
it knows if it should save main
Model
or relatedModel
first to preserve the relationit saves main
Model
ifsaved
,pk
valuesave_all=True
flag is setin those cases you don't have to split save into two calls (
save()
andsave_related()
)it supports also
ManyToMany
relationsit supports also optional
Through
model values for m2m relationsAdd possibility to customize
Through
model relation field names.By default
Through
model relation names default to related model name in lowercase.So in example like this:
To customize the names of fields/relation in Through model now you can use new parameters to
ManyToMany
:through_relation_name
- name of the field leading to the model in whichManyToMany
is declaredthrough_reverse_relation_name
- name of the field leading to the model to whichManyToMany
leads toExample: