(self, kwargs: dict)
| 768 | super().__setattr__(key, value) |
| 769 | |
| 770 | def _set_kwargs(self, kwargs: dict) -> set[str]: |
| 771 | meta = self._meta |
| 772 | |
| 773 | # Assign values and do type conversions |
| 774 | passed_fields = {*kwargs.keys()} | meta.fetch_fields |
| 775 | |
| 776 | for key, value in kwargs.items(): |
| 777 | if key in meta.fk_fields or key in meta.o2o_fields: |
| 778 | if value and not value._saved_in_db: |
| 779 | raise OperationalError( |
| 780 | f"You should first call .save() on {value} before referring to it" |
| 781 | ) |
| 782 | setattr(self, key, value) |
| 783 | passed_fields.add(meta.fields_map[key].source_field) |
| 784 | elif key in meta.fields_db_projection: |
| 785 | field_object = meta.fields_map[key] |
| 786 | if field_object.pk and field_object.generated: |
| 787 | self._custom_generated_pk = True |
| 788 | if value is None and not field_object.null: |
| 789 | raise ValueError(f"{key} is non nullable field, but null was passed") |
| 790 | setattr(self, key, field_object.to_python_value(value)) |
| 791 | elif key in meta.backward_fk_fields: |
| 792 | raise ConfigurationError( |
| 793 | "You can't set backward relations through init, change related model instead" |
| 794 | ) |
| 795 | elif key in meta.backward_o2o_fields: |
| 796 | raise ConfigurationError( |
| 797 | "You can't set backward one to one relations through init," |
| 798 | " change related model instead" |
| 799 | ) |
| 800 | elif key in meta.m2m_fields: |
| 801 | raise ConfigurationError( |
| 802 | "You can't set m2m relations through init, use m2m_manager instead" |
| 803 | ) |
| 804 | |
| 805 | return passed_fields |
| 806 | |
| 807 | @classmethod |
| 808 | def get_table(cls) -> Table: |
no test coverage detected