QDjango
|
The QDjangoModel class is the base class for all models. More...
#include <QDjangoModel.h>
Public Slots | |
bool | remove () |
bool | save () |
QString | toString () const |
Public Member Functions | |
QDjangoModel (QObject *parent=0) | |
QVariant | pk () const |
void | setPk (const QVariant &pk) |
Protected Member Functions | |
QObject * | foreignKey (const char *name) const |
void | setForeignKey (const char *name, QObject *value) |
Properties | |
QVariant | pk |
The QDjangoModel class is the base class for all models.
To declare your own model, create a class which inherits QDjangoModel and declare the database fields as properties using the Q_PROPERTY macro. You must then register the class with QDjango using QDjango::registerModel().
You can provide options for the model using the Q_CLASSINFO macro as follows:
Q_CLASSINFO("__meta__", "keyword1=value1 .. keywordN=valueN")
The following keywords are recognised for model options:
db_table
if provided, this is the name of the database table for the model, otherwise the lowercased class name will be usedYou can also provide additional information about a field using the Q_CLASSINFO macro, in the form:
Q_CLASSINFO("field_name", "keyword1=value1 .. keywordN=valueN")
The following keywords are recognised for field options:
auto_increment
if set to 'true', and if this field is the primary key, it will be marked as auto-increment. db_column
if provided, this is the name of the database column for the field, otherwise the field name will be used db_index
if set to 'true', an index will be created on this field. ignore_field
if set to 'true', this field will be ignored max_length
the maximum length of the field (used when creating the database table) null
if set to 'true', empty values will be stored as NULL. The default value is 'false'. primary_key
if set to 'true', this field will be used as the primary key. If no primary key is explicitly defined, an auto-increment integer field will be added. unique
if set to 'true', this field must be unique throughout the table. QDjangoModel::QDjangoModel | ( | QObject * | parent = 0 | ) |
Construct a new QDjangoModel.
parent |
QObject * QDjangoModel::foreignKey | ( | const char * | name | ) | const [protected] |
Retrieves the QDjangoModel pointed to by the given foreign-key.
name |
bool QDjangoModel::remove | ( | ) | [slot] |
Deletes the QDjangoModel from the database.
bool QDjangoModel::save | ( | ) | [slot] |
Saves the QDjangoModel to the database.
void QDjangoModel::setForeignKey | ( | const char * | name, |
QObject * | value | ||
) | [protected] |
Sets the QDjangoModel pointed to by the given foreign-key.
name | |
value |
value
. void QDjangoModel::setPk | ( | const QVariant & | pk | ) |
Sets the primary key for this QDjangoModel.
pk |
QString QDjangoModel::toString | ( | ) | const [slot] |
Returns a string representation of the model instance.
QVariant QDjangoModel::pk [read, write] |
Returns the primary key for this QDjangoModel.