django-contentrelations 1.1 documentation

Resources

BaseResource

class BaseResource

This class provides an abstraction for unifying access to different resources under a common interface. If a resource doesn’t have a FOO attribute, the subclass should defined a get_FOO method that returns the appropriate value.

missing_attribute_value

str Default: ''

The value returned when all methods of retrieving it has failed. Only used if BaseResource.raise_error_on_missing is False

raise_error_on_missing

bool Default: False

An AttributeError should be raised when all methods of retrieving it has failed.

instance

object

Set during instantiation, this is the instance used to resolve all attribute requests.

get_resource_type()

This is the get_FOO method used when attempting to resolve the resource_type attribute. By default it returns the verbose_name of the instance.

get_url()

This is the get_FOO method used when attempting to resolve the url attribute. by default it returns the value from instance.get_absolute_url()

ResourceList

class ResourceList

This class provides the registry of models to their sub-classed BaseResource models. It is instantiated for use in resource_list.

content_types_lookup() → Q object

Returns a Q object used for limiting ContentType objects for selection to only those registered.

get_for_instance(instance) → BaseResource
Parameters:instance – An instance of a Model

Returns the registered resource for the passed instance instantiated with that instance.

register(model_or_iterable, resource_class)
Parameters:
  • model_or_iterable (Model, tuple or list) – The Model or an iterable of Model to link with a resource class.
  • resource_class (BaseResource) – The BaseResource subclass to link with the model or models given.

resource_list

from contentrelations import resource_list

The instantiated ResourceList used for registering Models with their BaseResource sub-classes.

ResourceIterator

class ResourceIterator

This class wraps any iterator or sequence and returns each item’s registered Resource class.