evennia.objects.models

This module defines the database models for all in-game objects, that is, all objects that has an actual existence in-game.

Each database object is ‘decorated’ with a ‘typeclass’, a normal python class that implements all the various logics needed by the game in question. Objects created of this class transparently communicate with its related database object for storing all attributes. The admin should usually not have to deal directly with this database object layer.

Attributes are separate objects that store values persistently onto the database object. Like everything else, they can be accessed transparently through the decorating TypeClass.

class evennia.objects.models.ContentsHandler(obj)[source]

Bases: object

Handles and caches the contents of an object to avoid excessive lookups (this is done very often due to cmdhandler needing to look for object-cmdsets). It is stored on the ‘contents_cache’ property of the ObjectDB.

__init__(obj)[source]

Sets up the contents handler.

Parameters

obj (Object) – The object on which the handler is defined

load()[source]

Retrieves all objects from database. Used for initializing.

Returns

Objects (list of ObjectDB)

init()[source]

Re-initialize the content cache

get(exclude=None, content_type=None)[source]

Return the contents of the cache.

Parameters
  • exclude (Object or list of Object) – object(s) to ignore

  • content_type (str or None) – Filter list by a content-type. If None, don’t filter.

Returns

objects (list) – the Objects inside this location

add(obj)[source]

Add a new object to this location

Parameters

obj (Object) – object to add

remove(obj)[source]

Remove object from this location

Parameters

obj (Object) – object to remove

clear()[source]

Clear the contents cache and re-initialize

class evennia.objects.models.ObjectDB(*args, **kwargs)[source]

Bases: evennia.typeclasses.models.TypedObject

All objects in the game use the ObjectDB model to store data in the database. This is handled transparently through the typeclass system.

Note that the base objectdb is very simple, with few defined fields. Use attributes to extend your type class with new database-stored variables.

The TypedObject supplies the following (inherited) properties:

  • key - main name

  • name - alias for key

  • db_typeclass_path - the path to the decorating typeclass

  • db_date_created - time stamp of object creation

  • permissions - perm strings

  • locks - lock definitions (handler)

  • dbref - #id of object

  • db - persistent attribute storage

  • ndb - non-persistent attribute storage

The ObjectDB adds the following properties:

  • account - optional connected account (always together with sessid)

  • sessid - optional connection session id (always together with account)

  • location - in-game location of object

  • home - safety location for object (handler)

  • scripts - scripts assigned to object (handler from typeclass)

  • cmdset - active cmdset on object (handler from typeclass)

  • aliases - aliases for this object (property)

  • nicks - nicknames for other things in Evennia (handler)

  • sessions - sessions connected to this object (see also account)

  • has_account - bool if an active account is currently connected

  • contents - other objects having this object as location

  • exits - exits from this object

db_account

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Child.parent** is a **ForwardManyToOneDescriptor** instance.

db_sessid

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

db_location

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Child.parent** is a **ForwardManyToOneDescriptor** instance.

db_home

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Child.parent** is a **ForwardManyToOneDescriptor** instance.

db_destination

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Child.parent** is a **ForwardManyToOneDescriptor** instance.

db_cmdset_storage

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <evennia.objects.manager.ObjectDBManager object>
contents_cache[source]
property cmdset_storage

getter

property location

Get location

at_db_location_postsave(new)[source]

This is called automatically after the location field was saved, no matter how. It checks for a variable _safe_contents_update to know if the save was triggered via the location handler (which updates the contents cache) or not.

Parameters

new (bool) – Set if this location has not yet been saved before.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

property account

A wrapper for getting database field db_account.

db_account_id
db_attributes

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

db_destination_id
db_home_id
db_location_id
db_tags

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property destination

A wrapper for getting database field db_destination.

destinations_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Parent.children** is a **ReverseManyToOneDescriptor** instance.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

get_next_by_db_date_created(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=True, **kwargs)
get_previous_by_db_date_created(*, field=<django.db.models.fields.DateTimeField: db_date_created>, is_next=False, **kwargs)
hide_from_objects_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property home

A wrapper for getting database field db_home.

homes_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Parent.children** is a **ReverseManyToOneDescriptor** instance.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

locations_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Parent.children** is a **ReverseManyToOneDescriptor** instance.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

object_subscription_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

path = 'evennia.objects.models.ObjectDB'
receiver_object_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

scriptdb_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

**Parent.children** is a **ReverseManyToOneDescriptor** instance.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

sender_object_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

**Pizza.toppings** and **Topping.pizzas** are **ManyToManyDescriptor** instances.

Most of the implementation is delegated to a dynamically defined manager class built by **create_forward_many_to_many_manager()** defined below.

property sessid

A wrapper for getting database field db_sessid.

typename = 'SharedMemoryModelBase'