Receives dictionary of model that is about to be saved and populates the default value on the fields that have the default value set, but no actual value was passed by the user. :param new_kwargs: dictionary of model that is about to be saved :type new_kwarg
(cls, new_kwargs: dict)
| 235 | |
| 236 | @classmethod |
| 237 | def populate_default_values(cls, new_kwargs: dict) -> dict: |
| 238 | """ |
| 239 | Receives dictionary of model that is about to be saved and populates the default |
| 240 | value on the fields that have the default value set, but no actual value was |
| 241 | passed by the user. |
| 242 | |
| 243 | :param new_kwargs: dictionary of model that is about to be saved |
| 244 | :type new_kwargs: dict |
| 245 | :return: dictionary of model that is about to be saved |
| 246 | :rtype: dict |
| 247 | """ |
| 248 | for field_name, field in cls.ormar_config.model_fields.items(): |
| 249 | if field_name not in new_kwargs and field.has_default(use_server=False): |
| 250 | new_kwargs[field_name] = field.get_default() |
| 251 | # clear fields with server_default set as None |
| 252 | if ( |
| 253 | field.server_default is not None |
| 254 | and new_kwargs.get(field_name, None) is None |
| 255 | ): |
| 256 | new_kwargs.pop(field_name, None) |
| 257 | return new_kwargs |
| 258 | |
| 259 | @classmethod |
| 260 | def populate_onupdate_value( |