1 2 3 4 5 6 7 8 9 10 | def _object_to_query(obj):
values = [(f, '\'%s\'' % f.get_db_prep_save(f.value_from_object(obj))) for f in obj._meta.local_fields]
q = sql.InsertQuery(obj)
q.insert_values(values)
compiler = q.get_compiler('default')
# Normally, execute sets this, but we don't want to call execute
setattr(compiler, 'return_id', False)
stmt, params = compiler.as_sql()
stmt = stmt % params
return stmt
|
More like this
- print SQL statements by zuzelvp 2 years, 3 months ago
- Save a model using an arbitrary db connection by weswinham 2 years, 8 months ago
- Table Creation Using ORM Standalone by EliAndrewC 4 years, 3 months ago
- PositionField by jpwatts 3 years, 10 months ago
- Another means of updating a subset of a model's fields by insin 4 years, 6 months ago
Comments