Prepare a value to be used in a query by resolving it if it is an expression and otherwise calling the field's get_db_prep_save().
(self, field, value)
| 1717 | return sql, params |
| 1718 | |
| 1719 | def prepare_value(self, field, value): |
| 1720 | """ |
| 1721 | Prepare a value to be used in a query by resolving it if it is an |
| 1722 | expression and otherwise calling the field's get_db_prep_save(). |
| 1723 | """ |
| 1724 | if hasattr(value, "resolve_expression"): |
| 1725 | value = value.resolve_expression( |
| 1726 | self.query, allow_joins=False, for_save=True |
| 1727 | ) |
| 1728 | # Don't allow values containing Col expressions. They refer to |
| 1729 | # existing columns on a row, but in the case of insert the row |
| 1730 | # doesn't exist yet. |
| 1731 | if value.contains_column_references: |
| 1732 | raise ValueError( |
| 1733 | 'Failed to insert expression "%s" on %s. F() expressions ' |
| 1734 | "can only be used to update, not to insert." % (value, field) |
| 1735 | ) |
| 1736 | if value.contains_aggregate: |
| 1737 | raise FieldError( |
| 1738 | "Aggregate functions are not allowed in this query " |
| 1739 | "(%s=%r)." % (field.name, value) |
| 1740 | ) |
| 1741 | if value.contains_over_clause: |
| 1742 | raise FieldError( |
| 1743 | "Window expressions are not allowed in this query (%s=%r)." |
| 1744 | % (field.name, value) |
| 1745 | ) |
| 1746 | return field.get_db_prep_save(value, connection=self.connection) |
| 1747 | |
| 1748 | def pre_save_val(self, field, obj): |
| 1749 | """ |
nothing calls this directly
no test coverage detected