Database instances connect to a specific ClickHouse database for running queries, inserting data and other operations.
Initializes a database instance. Unless it’s readonly, the database will be created on the ClickHouse server if it does not already exist.
db_name
: name of the database to connect to.db_url
: URL of the ClickHouse server.username
: optional connection credentials.password
: optional connection credentials.readonly
: use a read-only connection.auto_create
: automatically create the database if it
does not exist (unless in readonly mode).timeout
: the connection timeout in seconds.verify_ssl_cert
: whether to verify the server’s
certificate when connecting via HTTPS.log_statements
: when True, all database statements are
logged.Adds a database setting that will be sent with every request. For
example, db.add_setting("max_execution_time", 10)
will
limit query execution time to 10 seconds. The name must be string, and
the value is converted to string in case it isn’t. To remove a setting,
pass None
as the value.
Counts the number of records in the model’s table.
model_class
: the model to count.conditions
: optional SQL conditions (contents of the
WHERE clause).Creates the database on the ClickHouse server if it does not already exist.
Creates a table for the given model class, if it does not exist already.
Checks whether a table for the given model class already exists. Note that this only checks for existence of a table with the expected name.
Deletes the database on the ClickHouse server.
Drops the database table of the given model class, if it exists.
Generates a model class from an existing table in the database. This can be used for querying tables which don’t have a corresponding model class, for example system tables.
table_name
: the table to create a model forsystem_table
: whether the table is a system table, or
belongs to the current databaseInsert records into the database.
model_instances
: any iterable containing instances of a
single model class.batch_size
: number of records to send per chunk (use a
lower number if your records are very large).Executes schema migrations.
migrations_package_name
- fully qualified name of the
Python package containing the migrations.up_to
- number of the last migration to apply.Selects records and returns a single page of model instances.
model_class
: the model class matching the query’s
table, or None
for getting back instances of an ad-hoc
model.order_by
: columns to use for sorting the query
(contents of the ORDER BY clause).page_num
: the page number (1-based), or -1 to get the
last page.page_size
: number of records to return per page.conditions
: optional SQL conditions (contents of the
WHERE clause).settings
: query settings to send as HTTP GET
parametersThe result is a namedtuple containing objects
(list),
number_of_objects
, pages_total
,
number
(of the current page), and
page_size
.
Performs a query and returns its output as text.
query
: the SQL query to execute.settings
: query settings to send as HTTP GET
parametersstream
: if true, the HTTP response from ClickHouse will
be streamed.Performs a query and returns a generator of model instances.
query
: the SQL query to execute.model_class
: the model class matching the query’s
table, or None
for getting back instances of an ad-hoc
model.settings
: query settings to send as HTTP GET
parametersExtends Exception
Raised when a database operation fails.
Extends Database
Initializes a database instance. Unless it’s readonly, the database will be created on the ClickHouse server if it does not already exist.
db_name
: name of the database to connect to.db_url
: URL of the ClickHouse server.username
: optional connection credentials.password
: optional connection credentials.readonly
: use a read-only connection.auto_create
: automatically create the database if it
does not exist (unless in readonly mode).timeout
: the connection timeout in seconds.verify_ssl_cert
: whether to verify the server’s
certificate when connecting via HTTPS.log_statements
: when True, all database statements are
logged.Adds a database setting that will be sent with every request. For
example, db.add_setting("max_execution_time", 10)
will
limit query execution time to 10 seconds. The name must be string, and
the value is converted to string in case it isn’t. To remove a setting,
pass None
as the value.
Counts the number of records in the model’s table.
model_class
: the model to count.conditions
: optional SQL conditions (contents of the
WHERE clause).Creates the database on the ClickHouse server if it does not already exist.
Creates a table for the given model class, if it does not exist already.
Creates a temporary table for the given model class, if it does not exist already. And you can specify the temporary table name explicitly.
Checks whether a table for the given model class already exists. Note that this only checks for existence of a table with the expected name.
Deletes the database on the ClickHouse server.
Drops the database table of the given model class, if it exists.
Generates a model class from an existing table in the database. This can be used for querying tables which don’t have a corresponding model class, for example system tables.
table_name
: the table to create a model forsystem_table
: whether the table is a system table, or
belongs to the current databaseInsert records into the database.
model_instances
: any iterable containing instances of a
single model class.batch_size
: number of records to send per chunk (use a
lower number if your records are very large).Executes schema migrations.
migrations_package_name
- fully qualified name of the
Python package containing the migrations.up_to
- number of the last migration to apply.Selects records and returns a single page of model instances.
model_class
: the model class matching the query’s
table, or None
for getting back instances of an ad-hoc
model.order_by
: columns to use for sorting the query
(contents of the ORDER BY clause).page_num
: the page number (1-based), or -1 to get the
last page.page_size
: number of records to return per page.conditions
: optional SQL conditions (contents of the
WHERE clause).settings
: query settings to send as HTTP GET
parametersThe result is a namedtuple containing objects
(list),
number_of_objects
, pages_total
,
number
(of the current page), and
page_size
.
Performs a query and returns its output as text.
query
: the SQL query to execute.settings
: query settings to send as HTTP GET
parametersstream
: if true, the HTTP response from ClickHouse will
be streamed.Performs a query and returns a generator of model instances.
query
: the SQL query to execute.model_class
: the model class matching the query’s
table, or None
for getting back instances of an ad-hoc
model.settings
: query settings to send as HTTP GET
parametersA base class for ORM models. Each model class represent a ClickHouse table. For example:
class CPUStats(Model):
timestamp = DateTimeField()
cpu_id = UInt16Field()
cpu_percent = Float32Field()
engine = Memory()
Creates a model instance, using keyword arguments as field values.
Since values are immediately converted to their Pythonic type, invalid
values will cause a ValueError
to be raised. Unrecognized
field names will cause an AttributeError
.
Returns the SQL statement for creating a table for this model.
Returns the SQL command for deleting this model’s table.
Returns an OrderedDict
of the model’s fields (from name
to Field
instance). If writable
is true, only
writable fields are included. Callers should not modify the
dictionary.
Create a model instance from a tab-separated line. The line may or
may not include a newline. The field_names
list must match
the fields defined in the model, but does not have to include all of
them.
line
: the TSV-formatted data.field_names
: names of the model fields in the
data.timezone_in_use
: the timezone to use when parsing dates
and datetimes. Some fields use their own timezones.database
: if given, sets the database that this
instance belongs to.Gets the Database
that this model instance belongs to.
Returns None
unless the instance was read from the database
or written to it.
Gets a Field
instance given its name, or
None
if not found.
Return True if some of the model’s fields use a function expression as a default value. This requires special handling when inserting instances.
Returns true if the model is marked as read only.
Returns true if the model represents a system table.
Returns true if the model represents a temporary table.
Returns a QuerySet
for selecting instances of this model
class.
Sets the Database
that this model instance belongs to.
This is done automatically when the instance is read from the database
or written to it.
Returns the model’s database table name. By default this is the class name converted to lowercase. Override this if you want to use a different table name.
Returns the instance as a bytestring ready to be inserted into the database.
Returns the instance’s column values as a dict.
include_readonly
: if false, returns only fields that
can be inserted into database.field_names
: an iterable of field names to return
(optional)Returns the instance’s column keys and values as a tab-separated line. A newline is not included. Fields that were not assigned a value are omitted.
include_readonly
: if false, returns only fields that
can be inserted into database.Returns the instance’s column values as a tab-separated line. A newline is not included.
include_readonly
: if false, returns only fields that
can be inserted into database.Extends Model
Creates a model instance, using keyword arguments as field values.
Since values are immediately converted to their Pythonic type, invalid
values will cause a ValueError
to be raised. Unrecognized
field names will cause an AttributeError
.
Returns the SQL statement for creating a table for this model.
Returns the SQL command for deleting this model’s table.
Returns an OrderedDict
of the model’s fields (from name
to Field
instance). If writable
is true, only
writable fields are included. Callers should not modify the
dictionary.
Create a model instance from a tab-separated line. The line may or
may not include a newline. The field_names
list must match
the fields defined in the model, but does not have to include all of
them.
line
: the TSV-formatted data.field_names
: names of the model fields in the
data.timezone_in_use
: the timezone to use when parsing dates
and datetimes. Some fields use their own timezones.database
: if given, sets the database that this
instance belongs to.Gets the Database
that this model instance belongs to.
Returns None
unless the instance was read from the database
or written to it.
Gets a Field
instance given its name, or
None
if not found.
Return True if some of the model’s fields use a function expression as a default value. This requires special handling when inserting instances.
Returns true if the model is marked as read only.
Returns true if the model represents a system table.
Returns true if the model represents a temporary table.
Returns a QuerySet
for selecting instances of this model
class.
Sets the Database
that this model instance belongs to.
This is done automatically when the instance is read from the database
or written to it.
Returns the model’s database table name. By default this is the class name converted to lowercase. Override this if you want to use a different table name.
Returns the instance as a bytestring ready to be inserted into the database.
Returns the instance’s column values as a dict.
include_readonly
: if false, returns only fields that
can be inserted into database.field_names
: an iterable of field names to return
(optional)Returns the instance’s column keys and values as a tab-separated line. A newline is not included. Fields that were not assigned a value are omitted.
include_readonly
: if false, returns only fields that
can be inserted into database.Returns the instance’s column values as a tab-separated line. A newline is not included.
include_readonly
: if false, returns only fields that
can be inserted into database.Extends Model
Model for Merge engine Predefines virtual _table column an controls that rows can’t be inserted to this table type https://clickhouse.tech/docs/en/single/index.html#document-table_engines/merge
Creates a model instance, using keyword arguments as field values.
Since values are immediately converted to their Pythonic type, invalid
values will cause a ValueError
to be raised. Unrecognized
field names will cause an AttributeError
.
Returns the SQL statement for creating a table for this model.
Returns the SQL command for deleting this model’s table.
Returns an OrderedDict
of the model’s fields (from name
to Field
instance). If writable
is true, only
writable fields are included. Callers should not modify the
dictionary.
Create a model instance from a tab-separated line. The line may or
may not include a newline. The field_names
list must match
the fields defined in the model, but does not have to include all of
them.
line
: the TSV-formatted data.field_names
: names of the model fields in the
data.timezone_in_use
: the timezone to use when parsing dates
and datetimes. Some fields use their own timezones.database
: if given, sets the database that this
instance belongs to.Gets the Database
that this model instance belongs to.
Returns None
unless the instance was read from the database
or written to it.
Gets a Field
instance given its name, or
None
if not found.
Return True if some of the model’s fields use a function expression as a default value. This requires special handling when inserting instances.
Returns true if the model is marked as read only.
Returns true if the model represents a system table.
Returns true if the model represents a temporary table.
Returns a QuerySet
for selecting instances of this model
class.
Sets the Database
that this model instance belongs to.
This is done automatically when the instance is read from the database
or written to it.
Returns the model’s database table name. By default this is the class name converted to lowercase. Override this if you want to use a different table name.
Returns the instance as a bytestring ready to be inserted into the database.
Returns the instance’s column values as a dict.
include_readonly
: if false, returns only fields that
can be inserted into database.field_names
: an iterable of field names to return
(optional)Returns the instance’s column keys and values as a tab-separated line. A newline is not included. Fields that were not assigned a value are omitted.
include_readonly
: if false, returns only fields that
can be inserted into database.Returns the instance’s column values as a tab-separated line. A newline is not included.
include_readonly
: if false, returns only fields that
can be inserted into database.Extends Model
Model class for use with a Distributed
engine.
Creates a model instance, using keyword arguments as field values.
Since values are immediately converted to their Pythonic type, invalid
values will cause a ValueError
to be raised. Unrecognized
field names will cause an AttributeError
.
Returns the SQL statement for creating a table for this model.
Returns the SQL command for deleting this model’s table.
Returns an OrderedDict
of the model’s fields (from name
to Field
instance). If writable
is true, only
writable fields are included. Callers should not modify the
dictionary.
Remember: Distributed table does not store any data, just provides distributed access to it.
So if we define a model with engine that has no defined table for data storage (see FooDistributed below), that table cannot be successfully created. This routine can automatically fix engine’s storage table by finding the first non-distributed model among your model’s superclasses.
class Foo(Model): … id = UInt8Field(1) … class FooDistributed(Foo, DistributedModel): … engine = Distributed(‘my_cluster’) … FooDistributed.engine.table None FooDistributed.fix_engine() FooDistributed.engine.table <class ‘main.Foo’>
However if you prefer more explicit way of doing things, you can always mention the Foo model twice without bothering with any fixes:
class FooDistributedVerbose(Foo, DistributedModel): … engine = Distributed(‘my_cluster’, Foo) FooDistributedVerbose.engine.table <class ‘main.Foo’>
See tests.test_engines:DistributedTestCase for more examples
Create a model instance from a tab-separated line. The line may or
may not include a newline. The field_names
list must match
the fields defined in the model, but does not have to include all of
them.
line
: the TSV-formatted data.field_names
: names of the model fields in the
data.timezone_in_use
: the timezone to use when parsing dates
and datetimes. Some fields use their own timezones.database
: if given, sets the database that this
instance belongs to.Gets the Database
that this model instance belongs to.
Returns None
unless the instance was read from the database
or written to it.
Gets a Field
instance given its name, or
None
if not found.
Return True if some of the model’s fields use a function expression as a default value. This requires special handling when inserting instances.
Returns true if the model is marked as read only.
Returns true if the model represents a system table.
Returns true if the model represents a temporary table.
Returns a QuerySet
for selecting instances of this model
class.
Sets the Database
that this model instance belongs to.
This is done automatically when the instance is read from the database
or written to it.
Returns the model’s database table name. By default this is the class name converted to lowercase. Override this if you want to use a different table name.
Returns the instance as a bytestring ready to be inserted into the database.
Returns the instance’s column values as a dict.
include_readonly
: if false, returns only fields that
can be inserted into database.field_names
: an iterable of field names to return
(optional)Returns the instance’s column keys and values as a tab-separated line. A newline is not included. Fields that were not assigned a value are omitted.
include_readonly
: if false, returns only fields that
can be inserted into database.Returns the instance’s column values as a tab-separated line. A newline is not included.
include_readonly
: if false, returns only fields that
can be inserted into database.Defines a model constraint.
Initializer. Expects an expression that ClickHouse will verify when inserting data.
Returns the SQL statement for defining this constraint during table creation.
Defines a data-skipping index.
Initializer.
expr
- a column, expression, or tuple of columns and
expressions to index.type
- the index type. Use one of the following methods
to specify the type: Index.minmax
, Index.set
,
Index.ngrambf_v1
, Index.tokenbf_v1
or
Index.bloom_filter
.granularity
- index block size (number of multiples of
the index_granularity
defined by the engine).An index that stores a Bloom filter containing values of the index expression.
false_positive
- the probability (between 0 and 1) of
receiving a false positive response from the filterReturns the SQL statement for defining this index during table creation.
An index that stores extremes of the specified expression (if the expression is tuple, then it stores extremes for each element of tuple). The stored info is used for skipping blocks of data like the primary key.
An index that stores a Bloom filter containing all ngrams from a block of data. Works only with strings. Can be used for optimization of equals, like and in expressions.
n
— ngram sizesize_of_bloom_filter_in_bytes
— Bloom filter size in
bytes (you can use large values here, for example 256 or 512, because it
can be compressed well).number_of_hash_functions
— The number of hash functions
used in the Bloom filter.random_seed
— The seed for Bloom filter hash
functions.An index that stores unique values of the specified expression (no more than max_rows rows, or unlimited if max_rows=0). Uses the values to check if the WHERE expression is not satisfiable on a block of data.
An index that stores a Bloom filter containing string tokens. Tokens are sequences separated by non-alphanumeric characters.
size_of_bloom_filter_in_bytes
— Bloom filter size in
bytes (you can use large values here, for example 256 or 512, because it
can be compressed well).number_of_hash_functions
— The number of hash functions
used in the Bloom filter.random_seed
— The seed for Bloom filter hash
functions.Extends Field
Extends Field
Abstract base class for all enum-type fields.
Extends Field
Abstract base class for all float-type fields.
Extends Field
Abstract base class for all integer-type fields.
Extends Field
Extends DateTimeField
Extends Field
Extends DecimalField
Extends DecimalField
Extends DecimalField
Extends Field
Base class for all decimal fields. Can also be used directly.
Extends BaseEnumField
Extends BaseEnumField
Extends FunctionOperatorsMixin
Abstract base class for all field types.
Extends StringField
Extends BaseFloatField
Extends BaseFloatField
Extends Field
Extends Field
Extends BaseIntField
Extends BaseIntField
Extends BaseIntField
Extends BaseIntField
Extends Field
Extends Field
Extends Field
Extends Field
Extends BaseIntField
Extends BaseIntField
Extends BaseIntField
Extends BaseIntField
Extends Field
Extends Engine
Extends Engine
Extends Engine
Extends Engine
Extends Engine
Buffers the data to write in RAM, periodically flushing it to another
table. Must be used in conjuction with a BufferModel
. Read
more here.
Extends Engine
The Merge engine (not to be confused with MergeTree) does not store data itself, but allows reading from any number of other tables simultaneously. Writing to a table is not supported https://clickhouse.tech/docs/en/engines/table-engines/special/merge/
Extends Engine
The Distributed engine by itself does not store data, but allows distributed query processing on multiple servers. Reading is automatically parallelized. During a read, the table indexes on remote servers are used, if there are any.
See full documentation here https://clickhouse.tech/docs/en/engines/table-engines/special/distributed/
cluster
: what cluster to access data fromtable
: underlying table that actually stores data. If
you are not specifying any table here, ensure that it can be inferred
from your model’s superclass (see
models.DistributedModel.fix_engine_table)sharding_key
: how to distribute data among shards when
inserting straightly into Distributed table, optionalExtends MergeTree
Extends MergeTree
Extends MergeTree
Extends Generic
A queryset is an object that represents a database query using a
specific Model
. It is lazy, meaning that it does not hit
the database until you iterate over its matching rows (model
instances).
Initializer. It is possible to create a queryset like this, but the
standard way is to use MyModel.objects_in(database)
.
Returns an AggregateQuerySet
over this query, with
args
serving as grouping fields and kwargs
serving as calculated fields. At least one calculated field is required.
For example:
Event.objects_in(database).filter(date__gt='2017-08-01').aggregate('event_type', count='count()')
is equivalent to:
SELECT event_type, count() AS count FROM event
WHERE data > '2017-08-01'
GROUP BY event_type
Returns the whole query as a SQL string.
Returns the contents of the query’s WHERE
or
PREWHERE
clause as a string.
Returns the number of matching model instances.
Deletes all records matched by this queryset’s conditions. Note that ClickHouse performs deletions in the background, so they are not immediate.
Adds a DISTINCT clause to the query, meaning that any duplicate rows in the results will be omitted.
Returns a copy of this queryset that excludes all rows matching the
conditions. Pass prewhere=True
to apply the conditions as
PREWHERE instead of WHERE.
Returns a copy of this queryset that includes only rows matching the
conditions. Pass prewhere=True
to apply the conditions as
PREWHERE instead of WHERE.
Adds a FINAL modifier to table, meaning data will be collapsed to
final version. Can be used with the CollapsingMergeTree
and
ReplacingMergeTree
engines only.
Adds a LIMIT BY clause to the query. - offset_limit
:
either an integer specifying the limit, or a tuple of integers (offset,
limit). - fields_or_expr
: the field names or expressions to
use in the clause.
Returns a copy of this queryset limited to the specified field names. Useful when there are large fields that are not needed, or for creating a subquery to use with an IN operator.
Returns a copy of this queryset with the ordering changed.
Returns the contents of the query’s ORDER BY
clause as a
string.
Returns a single page of model instances that match the queryset.
Note that order_by
should be used first, to ensure a
correct partitioning of records into pages.
page_num
: the page number (1-based), or -1 to get the
last page.page_size
: number of records to return per page.The result is a namedtuple containing objects
(list),
number_of_objects
, pages_total
,
number
(of the current page), and
page_size
.
Returns the selected fields or expressions as a SQL string.
Updates all records matched by this queryset’s conditions. Keyword arguments specify the field names and expressions to use for the update. Note that ClickHouse performs updates in the background, so they are not immediate.
Extends QuerySet
A queryset used for aggregation.
Initializer. Normally you should not call this but rather use
QuerySet.aggregate()
.
The grouping fields should be a list/tuple of field names from the model. For example:
('event_type', 'event_subtype')
The calculated fields should be a mapping from name to a ClickHouse aggregation function.
For example:
{'weekday': 'toDayOfWeek(event_date)', 'number_of_events': 'count()'}
At least one calculated field is required.
This method is not supported on AggregateQuerySet
.
Returns the whole query as a SQL string.
Returns the contents of the query’s WHERE
or
PREWHERE
clause as a string.
Returns the number of rows after aggregation.
Deletes all records matched by this queryset’s conditions. Note that ClickHouse performs deletions in the background, so they are not immediate.
Adds a DISTINCT clause to the query, meaning that any duplicate rows in the results will be omitted.
Returns a copy of this queryset that excludes all rows matching the
conditions. Pass prewhere=True
to apply the conditions as
PREWHERE instead of WHERE.
Returns a copy of this queryset that includes only rows matching the
conditions. Pass prewhere=True
to apply the conditions as
PREWHERE instead of WHERE.
Adds a FINAL modifier to table, meaning data will be collapsed to
final version. Can be used with the CollapsingMergeTree
and
ReplacingMergeTree
engines only.
This method lets you specify the grouping fields explicitly. The
args
must be names of grouping fields or calculated fields
that this queryset was created with.
Adds a LIMIT BY clause to the query. - offset_limit
:
either an integer specifying the limit, or a tuple of integers (offset,
limit). - fields_or_expr
: the field names or expressions to
use in the clause.
This method is not supported on AggregateQuerySet
.
Returns a copy of this queryset with the ordering changed.
Returns the contents of the query’s ORDER BY
clause as a
string.
Returns a single page of model instances that match the queryset.
Note that order_by
should be used first, to ensure a
correct partitioning of records into pages.
page_num
: the page number (1-based), or -1 to get the
last page.page_size
: number of records to return per page.The result is a namedtuple containing objects
(list),
number_of_objects
, pages_total
,
number
(of the current page), and
page_size
.
Returns the selected fields or expressions as a SQL string.
Updates all records matched by this queryset’s conditions. Keyword arguments specify the field names and expressions to use for the update. Note that ClickHouse performs updates in the background, so they are not immediate.
Adds WITH TOTALS modifier ot GROUP BY, making query return extra row with aggregate function calculated across all the rows. More information: https://clickhouse.tech/docs/en/query_language/select/#with-totals-modifier
Extends Cond, FunctionOperatorsMixin
Represents a database function call and its arguments. It doubles as a query condition when the function returns a boolean result.
Initializer.
Generates an SQL string for this function and its arguments. For
example if the function name is a symbol of a binary operator: (2.54 *
height
) For other functions: gcd(12, 300)
Extends Model
Contains information about parts of a table in the MergeTree family. This model operates only fields, described in the reference. Other fields are ignored. https://clickhouse.tech/docs/en/system_tables/system.parts/
Creates a model instance, using keyword arguments as field values.
Since values are immediately converted to their Pythonic type, invalid
values will cause a ValueError
to be raised. Unrecognized
field names will cause an AttributeError
.
Add a new part or partition from the ‘detached’ directory to the table.
settings
: Settings for executing request to ClickHouse
over db.raw() methodReturns: SQL Query
Returns the SQL statement for creating a table for this model.
Move a partition to the ‘detached’ directory and forget it.
settings
: Settings for executing request to ClickHouse
over db.raw() methodReturns: SQL Query
Delete a partition
settings
: Settings for executing request to ClickHouse
over db.raw() methodReturns: SQL Query
Returns the SQL command for deleting this model’s table.
Download a partition from another server.
zookeeper_path
: Path in zookeeper to fetch fromsettings
: Settings for executing request to ClickHouse
over db.raw() methodReturns: SQL Query
Returns an OrderedDict
of the model’s fields (from name
to Field
instance). If writable
is true, only
writable fields are included. Callers should not modify the
dictionary.
Create a backup of a partition.
settings
: Settings for executing request to ClickHouse
over db.raw() methodReturns: SQL Query
Create a model instance from a tab-separated line. The line may or
may not include a newline. The field_names
list must match
the fields defined in the model, but does not have to include all of
them.
line
: the TSV-formatted data.field_names
: names of the model fields in the
data.timezone_in_use
: the timezone to use when parsing dates
and datetimes. Some fields use their own timezones.database
: if given, sets the database that this
instance belongs to.Get all data from system.parts table
database
: A database object to fetch data from.conditions
: WHERE clause conditions. Database condition
is added automaticallyReturns: A list of SystemPart objects
Gets active data from system.parts table
database
: A database object to fetch data from.conditions
: WHERE clause conditions. Database and
active conditions are added automaticallyReturns: A list of SystemPart objects
Gets the Database
that this model instance belongs to.
Returns None
unless the instance was read from the database
or written to it.
Gets a Field
instance given its name, or
None
if not found.
Return True if some of the model’s fields use a function expression as a default value. This requires special handling when inserting instances.
Returns true if the model is marked as read only.
Returns true if the model represents a system table.
Returns true if the model represents a temporary table.
Returns a QuerySet
for selecting instances of this model
class.
Sets the Database
that this model instance belongs to.
This is done automatically when the instance is read from the database
or written to it.
Returns the instance as a bytestring ready to be inserted into the database.
Returns the instance’s column values as a dict.
include_readonly
: if false, returns only fields that
can be inserted into database.field_names
: an iterable of field names to return
(optional)Returns the instance’s column keys and values as a tab-separated line. A newline is not included. Fields that were not assigned a value are omitted.
include_readonly
: if false, returns only fields that
can be inserted into database.Returns the instance’s column values as a tab-separated line. A newline is not included.
include_readonly
: if false, returns only fields that
can be inserted into database.