Package pyamf :: Package adapters :: Module _django_db_models_base

[hide private]
[frames] | no frames]

# Module _django_db_models_base

source code

`django.db.models` adapter module.

See Also: Django Project

Since: 0.4.1

Classes | [hide private]

| DjangoReferenceCollection This helper class holds a dict of klass to pk/objects loaded from the underlying db.
| DjangoClassAlias

Functions | [hide private]

Instance of DjangoReferenceCollection

getDjangoObjects(context) Returns a reference to the `django_objects` on the context. | source code

writeDjangoObject(self, obj, *args, **kwargs) The Django ORM creates new instances of objects for each db request. | source code

install_django_reference_model_hook(mod) Called when pyamf.amf0 or pyamf.amf3 are imported. | source code

Imports: Model, fields, related, files, datetime, pyamf, imports

Function Details | [hide private]

### getDjangoObjects(context)

source code

Returns a reference to the `django_objects` on the context. If it doesn't exist then it is created.

Parameters:
  - `context` (Instance of pyamf.BaseContext) - The context to load the `django_objects` index from.
Returns: Instance of DjangoReferenceCollection
  The `django_objects` index reference.

Since: 0.5

### writeDjangoObject(self, obj, *args, **kwargs)

source code

The Django ORM creates new instances of objects for each db request. This is a problem for PyAMF as it uses the id(obj) of the object to do reference checking.

We could just ignore the problem, but the objects are conceptually the same so the effort should be made to attempt to resolve references for a given object graph.

We create a new map on the encoder context object which contains a dict of `object.__class__: {key1: object1, key2: object2, .., keyn: objectn}`. We use the primary key to do the reference checking.

Since: 0.5

### install_django_reference_model_hook(mod)

source code

Called when pyamf.amf0 or pyamf.amf3 are imported. Attaches the writeDjangoObject method to the `Encoder` class in that module.

Parameters:
  - `mod` - The module imported.

Since: 0.4.1