Expression to use DEFAULT keyword during insert otherwise the underlying expression.
| 1309 | |
| 1310 | |
| 1311 | class DatabaseDefault(Expression): |
| 1312 | """ |
| 1313 | Expression to use DEFAULT keyword during insert otherwise the underlying |
| 1314 | expression. |
| 1315 | """ |
| 1316 | |
| 1317 | def __init__(self, expression, output_field=None): |
| 1318 | super().__init__(output_field) |
| 1319 | self.expression = expression |
| 1320 | |
| 1321 | def get_source_expressions(self): |
| 1322 | return [self.expression] |
| 1323 | |
| 1324 | def set_source_expressions(self, exprs): |
| 1325 | (self.expression,) = exprs |
| 1326 | |
| 1327 | def resolve_expression( |
| 1328 | self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False |
| 1329 | ): |
| 1330 | resolved_expression = self.expression.resolve_expression( |
| 1331 | query=query, |
| 1332 | allow_joins=allow_joins, |
| 1333 | reuse=reuse, |
| 1334 | summarize=summarize, |
| 1335 | for_save=for_save, |
| 1336 | ) |
| 1337 | # Defaults used outside an INSERT context should resolve to their |
| 1338 | # underlying expression. |
| 1339 | if not for_save: |
| 1340 | return resolved_expression |
| 1341 | return DatabaseDefault( |
| 1342 | resolved_expression, output_field=self._output_field_or_none |
| 1343 | ) |
| 1344 | |
| 1345 | def as_sql(self, compiler, connection): |
| 1346 | if not connection.features.supports_default_keyword_in_insert: |
| 1347 | return compiler.compile(self.expression) |
| 1348 | return "DEFAULT", () |
| 1349 | |
| 1350 | |
| 1351 | class Col(Expression): |
no outgoing calls
no test coverage detected