Add through fields, load_all() method and make through models optional
0.9.6
Important
-
Through
model forManyToMany
relations now becomes optional. It's not a breaking change
since if you provide it everything works just fine as it used to. So if you don't want or need any additional
fields onThrough
model you can skip it. Note that it's going to be created for you automatically and
still has to be included in example inalembic
migrations.
If you want to delete existing one check the default naming convention to adjust your existing database structure.Note that you still need to provide it if you want to
customize theThrough
model name or the database table name.
Features
- Add
update
method toQuerysetProxy
so now it's possible to update related models directly from parent model
inManyToMany
relations and in reverseForeignKey
relations. Note that update like inQuerySet
update
returns number of
updated models and does not update related models in place on parent model. To get the refreshed data on parent model you need to refresh
the related models (i.e.await model_instance.related.all()
) - Add
load_all(follow=False, exclude=None)
model method that allows to load current instance of the model
with all related models in one call. By default it loads only directly related models but setting
follow=True
causes traversing the tree (avoiding loops). You can also passexclude
parameter
that works the same asQuerySet.exclude_fields()
method. - Added possibility to add more fields on
Through
model forManyToMany
relationships:- name of the through model field is the lowercase name of the Through class
- you can pass additional fields when calling
add(child, **kwargs)
on relation (onQuerysetProxy
) - you can pass additional fields when calling
create(**kwargs)
on relation (onQuerysetProxy
)
when one of the keyword arguments should be the through model name with a dict of values - you can order by on through model fields
- you can filter on through model fields
- you can include and exclude fields on through models
- through models are attached only to related models (i.e. if you query from A to B -> only on B)
- note that through models are explicitly loaded without relations -> relation is already populated in ManyToMany field.
- note that just like before you cannot declare the relation fields on through model, they will be populated for you by
ormar
,
but now if you try to do soModelDefinitionError
will be thrown - check the updated ManyToMany relation docs for more information
Other
- Updated docs and api docs
- Refactors and optimisations mainly related to filters, exclusions and order bys