Part of twistar.dbobject View In Hierarchy
Known subclasses: twistar.tests.utils.Avatar, twistar.tests.utils.Blogpost, twistar.tests.utils.Boy, twistar.tests.utils.Category, twistar.tests.utils.Coltest, twistar.tests.utils.FakeObject, twistar.tests.utils.FavoriteColor, twistar.tests.utils.Girl, twistar.tests.utils.Nickname, twistar.tests.utils.Picture, twistar.tests.utils.User (hide last 8 again) ... and 8 more
See Also | Relationship ,
HasMany , HasOne , HABTM , BelongsTo |
Split Table into Classes Show Methods in One Table
Line # | Kind | Name | Docs |
---|---|---|---|
0 | Class Variable | HASMANY | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has many of, for instance 'users' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasMany
for more information. |
0 | Class Variable | HASONE | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has one of, for instance 'location' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasOne for
more information. |
0 | Class Variable | HABTM | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has many of (and which in turn has many of this current object type),
for instance a teacher has and belongs to many students. Both the
Student and Teacher classes should have a class
variable that is HABTM = ['teachers'] and HABTM =
['students'] , respectively. If an element is a dict ,
then it should minimally have a name attribute (with a value
the same as if the element were a string) and then any additional options.
See Relationship
and HABTM
for more information. |
0 | Class Variable | BELONGSTO | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class belongs to, for instance 'user' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and BelongsTo for
more information. |
0 | Class Variable | TABLENAME | If specified, use the given tablename as the one for this object.
Otherwise, use the lowercase, plural version of this class's name. See the
DBObject.tablename
method. |
61 | Method | __init__ | Constructor. DO NOT OVERWRITE. Use the DBObject.afterInit
method. |
80 | Method | updateAttrs | Set the attributes of this object based on the given
dict . |
91 | Method | save | Save this object to the database. Validation is performed first; if the
validation fails (that is, if obj.errors.isEmpty() is False)
then the object will not be saved. To test for errors, use
obj.errors.isEmpty() . |
114 | Method | validate | No summary |
124 | Method | isValid | This method first calls validate
and then returns a deferred that returns True if there were no errors and
False otherwise. |
134 | Method | beforeCreate | Method called before a new object is created. Classes can overwrite
this method. If False is returned, then the object is not saved in the
database. This method may return a Deferred . |
142 | Method | beforeUpdate | Method called before an existing object is updated. Classes can
overwrite this method. If False is returned, then the object is not saved
in the database. This method may return a Deferred . |
150 | Method | beforeSave | Method called before an object is saved. Classes can overwrite this
method. If False is returned, then the object is not saved in the database.
This method may return a Deferred . |
161 | Method | afterInit | Method called when a new DBObject is
instantiated. Classes can overwrite this method. This method may return a
Deferred . |
168 | Method | beforeDelete | Method called before a DBObject is deleted.
Classes can overwrite this method. If False is returned, then the DBObject is not
deleted from database. This method may return a Deferred . |
222 | Method | refresh | Update the properties for this object from the database. |
231 | Method | toHash | Convert this object to a dictionary. |
257 | Method | delete | Delete this instance from the database. Calls beforeDelete
before deleting from the database. |
284 | Method | loadRelations | No summary |
313 | Class Method | addRelation | Add a relationship to the given Class. |
342 | Class Method | initRelationshipCache | Initialize the cache of relationship objects for this class. |
353 | Class Method | tablename | Get the tablename for the given class. If the class has a
TABLENAME variable then that will be used - otherwise, it is
is inferred from the class name. |
368 | Class Method | findOrCreate | Find all instances of a given class based on the attributes given (just
like findBy ). |
382 | Class Method | findBy | Find all instances of the given class based on an exact match of attributes. |
396 | Class Method | find | Find instances of a given class. |
428 | Class Method | count | Count instances of a given class. |
444 | Class Method | all | Get all instances of the given class in the database. Note that this is
the equivalent of calling find with no
arguments. |
456 | Class Method | deleteAll | Delete all instances of klass in the database without
instantiating the records first or invoking callbacks (beforeDelete
is not called). This will run a single SQL DELETE statement in the
database. |
473 | Class Method | exists | Find whether or not at least one instance of the given
klass exists, optionally with specific conditions specified in
where . |
489 | Method | __str__ | Get the string version of this object. |
501 | Method | __getattribute__ | Get the given attribute. |
520 | Method | __eq__ | Determine if this object is the same as another (only taking the type of
the other class and it's id into account). |
534 | Method | __neq__ | Determine if this object is not the same as another (only taking the
type of the other class and it's id into account). |
176 | Method | _create | Method to actually create an object in the DB. Handles calling this
class's beforeCreate
followed by it's beforeSave
method. |
199 | Method | _update | Method to actually save an existing object in the DB. Handles calling
this class's beforeUpdate
and beforeSave
methods. |
Inherited from Validator:
Line # | Kind | Name | Docs |
---|---|---|---|
0 | Class Variable | VALIDATIONS | A list of functions to call when testing whether or not a
particular instance is valid. |
95 | Class Method | clearValidations | Clear the given class's validations. |
103 | Class Method | addValidator | Add a function to the given classes validation list. |
121 | Class Method | validatesPresenceOf | A validator to test whether or not some named properties are set. For
those named properties that are not set, an error will be recorded in
obj.errors . |
137 | Class Method | validatesUniquenessOf | A validator to test whether or not some named properties are unique. For
those named properties that are not unique, an error will be recorded in
obj.errors . |
153 | Class Method | validatesLengthOf | No summary |
175 | Class Method | _validate | Validate a given object using all of the set validators for the objects
class. If errors are found, they will be recorded in the objects
errors property. |
Line # | Kind | Name | Docs |
---|---|---|---|
520 | Method | __eq__ | Determine if this object is the same as another (only taking the type of
the other class and it's id into account). |
501 | Method | __getattribute__ | Get the given attribute. |
61 | Method | __init__ | Constructor. DO NOT OVERWRITE. Use the DBObject.afterInit
method. |
534 | Method | __neq__ | Determine if this object is not the same as another (only taking the
type of the other class and it's id into account). |
489 | Method | __str__ | Get the string version of this object. |
313 | Class Method | addRelation | Add a relationship to the given Class. |
103 | Class Method | addValidator | Add a function to the given classes validation list. |
161 | Method | afterInit | Method called when a new DBObject is
instantiated. Classes can overwrite this method. This method may return a
Deferred . |
444 | Class Method | all | Get all instances of the given class in the database. Note that this is
the equivalent of calling find with no
arguments. |
134 | Method | beforeCreate | Method called before a new object is created. Classes can overwrite
this method. If False is returned, then the object is not saved in the
database. This method may return a Deferred . |
168 | Method | beforeDelete | Method called before a DBObject is deleted.
Classes can overwrite this method. If False is returned, then the DBObject is not
deleted from database. This method may return a Deferred . |
150 | Method | beforeSave | Method called before an object is saved. Classes can overwrite this
method. If False is returned, then the object is not saved in the database.
This method may return a Deferred . |
142 | Method | beforeUpdate | Method called before an existing object is updated. Classes can
overwrite this method. If False is returned, then the object is not saved
in the database. This method may return a Deferred . |
0 | Class Variable | BELONGSTO | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class belongs to, for instance 'user' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and BelongsTo for
more information. |
95 | Class Method | clearValidations | Clear the given class's validations. |
428 | Class Method | count | Count instances of a given class. |
257 | Method | delete | Delete this instance from the database. Calls beforeDelete
before deleting from the database. |
456 | Class Method | deleteAll | Delete all instances of klass in the database without
instantiating the records first or invoking callbacks (beforeDelete
is not called). This will run a single SQL DELETE statement in the
database. |
473 | Class Method | exists | Find whether or not at least one instance of the given
klass exists, optionally with specific conditions specified in
where . |
396 | Class Method | find | Find instances of a given class. |
382 | Class Method | findBy | Find all instances of the given class based on an exact match of attributes. |
368 | Class Method | findOrCreate | Find all instances of a given class based on the attributes given (just
like findBy ). |
0 | Class Variable | HABTM | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has many of (and which in turn has many of this current object type),
for instance a teacher has and belongs to many students. Both the
Student and Teacher classes should have a class
variable that is HABTM = ['teachers'] and HABTM =
['students'] , respectively. If an element is a dict ,
then it should minimally have a name attribute (with a value
the same as if the element were a string) and then any additional options.
See Relationship
and HABTM
for more information. |
0 | Class Variable | HASMANY | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has many of, for instance 'users' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasMany
for more information. |
0 | Class Variable | HASONE | A list made up of some number of strings and
dict s. If an element is a string, it represents what the
class has one of, for instance 'location' . If an element is a
dict , then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasOne for
more information. |
342 | Class Method | initRelationshipCache | Initialize the cache of relationship objects for this class. |
124 | Method | isValid | This method first calls validate
and then returns a deferred that returns True if there were no errors and
False otherwise. |
284 | Method | loadRelations | No summary |
222 | Method | refresh | Update the properties for this object from the database. |
91 | Method | save | Save this object to the database. Validation is performed first; if the
validation fails (that is, if obj.errors.isEmpty() is False)
then the object will not be saved. To test for errors, use
obj.errors.isEmpty() . |
0 | Class Variable | TABLENAME | If specified, use the given tablename as the one for this object.
Otherwise, use the lowercase, plural version of this class's name. See the
DBObject.tablename
method. |
353 | Class Method | tablename | Get the tablename for the given class. If the class has a
TABLENAME variable then that will be used - otherwise, it is
is inferred from the class name. |
231 | Method | toHash | Convert this object to a dictionary. |
80 | Method | updateAttrs | Set the attributes of this object based on the given
dict . |
114 | Method | validate | No summary |
153 | Class Method | validatesLengthOf | No summary |
121 | Class Method | validatesPresenceOf | A validator to test whether or not some named properties are set. For
those named properties that are not set, an error will be recorded in
obj.errors . |
137 | Class Method | validatesUniquenessOf | A validator to test whether or not some named properties are unique. For
those named properties that are not unique, an error will be recorded in
obj.errors . |
0 | Class Variable | VALIDATIONS | A list of functions to call when testing whether or not a
particular instance is valid. |
176 | Method | _create | Method to actually create an object in the DB. Handles calling this
class's beforeCreate
followed by it's beforeSave
method. |
199 | Method | _update | Method to actually save an existing object in the DB. Handles calling
this class's beforeUpdate
and beforeSave
methods. |
175 | Class Method | _validate | Validate a given object using all of the set validators for the objects
class. If errors are found, they will be recorded in the objects
errors property. |
list
made up of some number of strings and
dict
s. If an element is a string, it represents what the
class has many of, for instance 'users'
. If an element is a
dict
, then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasMany
for more information.
list
made up of some number of strings and
dict
s. If an element is a string, it represents what the
class has one of, for instance 'location'
. If an element is a
dict
, then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and HasOne
for
more information.
list
made up of some number of strings and
dict
s. If an element is a string, it represents what the
class has many of (and which in turn has many of this current object type),
for instance a teacher has and belongs to many students. Both the
Student
and Teacher
classes should have a class
variable that is HABTM = ['teachers']
and HABTM =
['students']
, respectively. If an element is a dict
,
then it should minimally have a name
attribute (with a value
the same as if the element were a string) and then any additional options.
See Relationship
and HABTM
for more information.
list
made up of some number of strings and
dict
s. If an element is a string, it represents what the
class belongs to, for instance 'user'
. If an element is a
dict
, then it should minimally have a name
attribute (with a value the same as if the element were a string) and then
any additional options. See Relationship
and BelongsTo
for
more information.
DBObject.tablename
method.
DBObject.afterInit
method.Parameters | kwargs | An optional dictionary containing the properties that should be initially set for this object. |
See Also | DBObject.afterInit |
dict
.Parameters | kwargs | A dict whose keys will be turned into properties and whose
values will then be assigned to those properties. |
obj.errors.isEmpty()
is False)
then the object will not be saved. To test for errors, use
obj.errors.isEmpty()
.Returns | A Deferred object. If a callback is added to that deferred
the value of the saved (or unsaved if there are errors) object will be
returned. | |
See Also | Validator , Errors |
DeferredList
). When this
deferred is finished, this object's errors dictionary property will either
be empty or will contain the errors from this object (keys are property
names, values are the error messages describing the error).validate
and then returns a deferred that returns True if there were no errors and
False otherwise.Deferred
.Deferred
.Deferred
.
This method is called after beforeCreate
when an object is being created, and after beforeUpdate
when an existing object (whose id
is not None
) is
being saved.
DBObject
is
instantiated. Classes can overwrite this method. This method may return a
Deferred
.beforeCreate
followed by it's beforeSave
method.Returns | A Deferred object. If a callback is added to that deferred
the value of the saved object will be returned (unless the beforeCreate
or beforeSave
methods returns False , in which case the unsaved object will
be returned). |
beforeUpdate
and beforeSave
methods.Returns | A Deferred object. If a callback is added to that deferred
the value of the saved object will be returned (unless the beforeUpdate
or beforeSave
methods returns False , in which case the unsaved object will
be returned). |
Returns | A Deferred object. |
Parameters | includeBlank | Boolean representing whether or not properties that have not been set should be included (the initial property list is retrieved from the schema of the database for the given class's schema). |
exclue | A list of properties to ignore when creating the
dict to return. | |
base | An initial base dict to add this objects properties to. | |
Returns | A dict formed from the properties and values of this object. |
beforeDelete
before deleting from the database.Returns | A Deferred . |
User
(named user
) that has
many Address
es and has one Avatar
, you could call
user.loadRelations('addresses',
'avatar').addCallback('handleUser')
instead of having to call
user.addresses.get()
and user.avatar.get()
and
assign callbacks to the results of those calls. In the first case, the
function handleUser
would accept one argument, which will be a
dictionary whose keys are the property names and whose values are the
results of the get()
calls. This just makes it easier to load
multiple properties at once, without having to create a long list of
callbacks.
If the method is called without any arguments, then all relations will loaded.
Returns | A Deferred . |
Parameters | klass | The class extending this one. |
relation | Either a string with the name of property to create for this class or a
dictionary decribing the relationship. For instance, if a User HasMany Pictures
then the relation could either by 'pictures' or a dictionary with at least
one "name" key, as in {'name': 'pictures', ...}
along with other options. | |
rtype | The relationship type. It should be a key value from the
TYPES class variable in the class Relationship . |
TABLENAME
variable then that will be used - otherwise, it is
is inferred from the class name.Parameters | klass | The class to get the tablename for. |
findBy
).
If a match isn't found, create a new instance and return that.
For instance: User.find(first_name='Bob',
last_name='Smith')
Will return all matches.
Parameters | id | The integer of the klass to find. For instance,
Klass.find(1) will return an instance of Klass from the row
with an id of 1 (unless it isn't found, in which case None is
returned). |
where | A list whose first element is the string version of the
condition with question marks in place of any parameters. Further elements
of the list should be the values of any parameters specified.
For instance, ['first_name = ? AND age > ?', 'Bob', 21] . | |
group | A str describing the grouping, like
group='first_name' . | |
limit | An int specifying the limit of the results. If this is 1,
then the return value will be either an instance of klass or
None . | |
orderby | A str describing the ordering, like orderby='first_name
DESC' . | |
Returns | A Deferred which returns the following to a callback: If id is
specified (or limit is 1) then a single instance of
klass will be returned if one is found that fits the criteria,
None otherwise. If id is not specified and limit
is not 1, then a list will be returned with all matching
results. |
Parameters | where | An optional list whose first element is the string version of
the condition with question marks in place of any parameters. Further
elements of the list should be the values of any parameters
specified. For instance, ['first_name = ? AND age > ?', 'Bob',
21] . |
Returns | A Deferred which returns the total number of db records to a
callback. |
find
with no
arguments.Returns | A Deferred which returns the following to a callback: A
list containing all of the instances in the database. |
klass
in the database without
instantiating the records first or invoking callbacks (beforeDelete
is not called). This will run a single SQL DELETE statement in the
database.Parameters | where | Conditionally delete instances. This parameter is of the same form found
in find . |
Returns | A Deferred . |
klass
exists, optionally with specific conditions specified in
where
.Parameters | where | Conditionally find instances. This parameter is of the same form found in
find . |
Returns | A Deferred which returns the following to a callback: A
boolean as to whether or not at least one object was found. |
Parameters | name | The name of the property to get. |
Returns | If the name is a relationship based property, then a Relationship
instance will be returned. Otherwise the set property of the class will be
returned. |