Mapper

Mapper

class save_to_db.core.utils.mapper.Mapper[source]

This class automatically sets up reverse relations for all items.

item_added_to_bulk(item, bulk_item)[source]

Called when an item is added to a bulk item, for example:

bulk_item.add(single_item)
Parameters:
  • item – A single item added to the bulk_item.
  • bulk_item – Bulk item containing item.
item_created(item)[source]

Called when an instance of ItemBase is created.

Parameters:item – An instance of created item.
item_deleted(item)[source]

Called when an item is deleted, for example:

item.delete()
Parameters:item – Deleted item.
item_removed_from_bulk(item, bulk_item)[source]

Called when an item is removed from a bulk item, for example:

bulk_item.remove(single_item)
Parameters:
  • item – A single item removed from the bulk_item.
  • bulk_item – Bulk item that was containing item.
item_value_deleted(item, key, old_value)[source]

Called when an item attribute is deleted, for example:

del item[key]
Parameters:
  • item – An item whose attribute is deleted.
  • key – Deleted attribute name.
  • old_value – Deleted attribute value.
item_value_set(item, key, old_value, new_value)[source]

Called when an item attribute is set, for example:

item[key] = new_value
Parameters:
  • item – An item whose attribute is set.
  • key – Attribute name of the item.
  • old_value – Old attribute value.
  • new_value – New attribute value.
iter_pointing_items(item, pointing_cls=None, pointing_key=None)[source]

A generator that yields items that point to a curtain item. to automatically adjust relationships.

Parameters:
  • item – an instance of Item class to which other items must point.
  • pointing_cls – Subclass of Item. If it is not None then only instances of this class are yielded.
  • pointing_key – If it is not None then only items that point using the same key are yielded.
Returns:

A generator of tupltes with two items, pointing key and pointing item.