-class EntityProxyField(object):
- descriptor_class = None
-
- def __init__(self, *args, **kwargs):
- if self.descriptor_class is None:
- raise NotImplementedError('EntityProxyField subclasses must specify a descriptor_class.')
-
- def actually_contribute_to_class(self, sender, **kwargs):
- sender._entity_meta.add_proxy_field(self)
- setattr(sender, self.attname, self.descriptor_class(self))
-
- def contribute_to_class(self, cls, name):
- if issubclass(cls, Entity):
- self.name = name
- self.attname = name
- entity_class_prepared.connect(self.actually_contribute_to_class, sender=cls)
- else:
- raise FieldError('%s instances can only be declared on Entity subclasses.' % self.__class__.__name__)
-
- def formfield(self, *args, **kwargs):
- raise NotImplementedError('EntityProxyField subclasses must implement a formfield method.')
-
- def value_from_object(self, obj):
- return getattr(obj, self.attname)
-
-
-class AttributeFieldDescriptor(object):