Duplicate a model, optionally choose which fields to include, exclude and change. :param include: fields to include in new model :param exclude: fields to exclude from new model, as with values this takes precedence over include :param update: values to change/add i
(
self: 'Model',
*,
include: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None,
exclude: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None,
update: Optional['DictStrAny'] = None,
deep: bool = False,
)
| 648 | return m |
| 649 | |
| 650 | def copy( |
| 651 | self: 'Model', |
| 652 | *, |
| 653 | include: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None, |
| 654 | exclude: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None, |
| 655 | update: Optional['DictStrAny'] = None, |
| 656 | deep: bool = False, |
| 657 | ) -> 'Model': |
| 658 | """ |
| 659 | Duplicate a model, optionally choose which fields to include, exclude and change. |
| 660 | |
| 661 | :param include: fields to include in new model |
| 662 | :param exclude: fields to exclude from new model, as with values this takes precedence over include |
| 663 | :param update: values to change/add in the new model. Note: the data is not validated before creating |
| 664 | the new model: you should trust this data |
| 665 | :param deep: set to `True` to make a deep copy of the model |
| 666 | :return: new model instance |
| 667 | """ |
| 668 | |
| 669 | values = dict( |
| 670 | self._iter(to_dict=False, by_alias=False, include=include, exclude=exclude, exclude_unset=False), |
| 671 | **(update or {}), |
| 672 | ) |
| 673 | |
| 674 | # new `__fields_set__` can have unset optional fields with a set value in `update` kwarg |
| 675 | if update: |
| 676 | fields_set = self.__fields_set__ | update.keys() |
| 677 | else: |
| 678 | fields_set = set(self.__fields_set__) |
| 679 | |
| 680 | return self._copy_and_set_values(values, fields_set, deep=deep) |
| 681 | |
| 682 | @classmethod |
| 683 | def schema(cls, by_alias: bool = True, ref_template: str = default_ref_template) -> 'DictStrAny': |
no test coverage detected