Returns a FieldInfo instance with populated default (static) or default_factory (function). If the field is a autoincrement primary key the default is None. Otherwise field have to has either default, or default_factory populated. If all default conditions f
(self, use_server: bool = False)
| 150 | return base |
| 151 | |
| 152 | def default_value(self, use_server: bool = False) -> Optional[dict]: |
| 153 | """ |
| 154 | Returns a FieldInfo instance with populated default |
| 155 | (static) or default_factory (function). |
| 156 | If the field is a autoincrement primary key the default is None. |
| 157 | Otherwise field have to has either default, or default_factory populated. |
| 158 | |
| 159 | If all default conditions fail None is returned. |
| 160 | |
| 161 | Used in converting to pydantic FieldInfo. |
| 162 | |
| 163 | :param use_server: flag marking if server_default should be |
| 164 | treated as default value, default False |
| 165 | :type use_server: bool |
| 166 | :return: returns a call to pydantic.Field |
| 167 | which is returning a FieldInfo instance |
| 168 | :rtype: Optional[pydantic.FieldInfo] |
| 169 | """ |
| 170 | if self.is_auto_primary_key(): |
| 171 | return dict(default=None) |
| 172 | if self.has_default(use_server=use_server): |
| 173 | default = ( |
| 174 | self.ormar_default |
| 175 | if self.ormar_default is not None |
| 176 | else self.server_default |
| 177 | ) |
| 178 | if callable(default): |
| 179 | return dict(default_factory=default) |
| 180 | return dict(default=default) |
| 181 | return None |
| 182 | |
| 183 | @overload |
| 184 | def get_default( |
no test coverage detected