| Trees | Indices | Help |
|
|---|
|
|
Extendable object.
An extendable object that enables an instance to be obtained as its class's farthest descendant.
Additionally, fields can be defined that would be added only to a direct subclass. This can be useful to automatically add relationships to subclasses so that relationships exist in the subclasses but not in the parents, allowing the same field name to be used for different types of relationships.
Further, the class that inherits from Extendable may
specify which field initialization arguments subclasses may override.
Subclasses can override the arguments by adding values to a dict in an inner class.
Adding fields is done by adding an Extend inner class.
Three fields can be used in the Extend inner class:
fields: This is a dict that
describes what the fields to be added in the subclass are. The format
is as follows :
{field_name : (field_class, args, kwargs, repl_args, repl_kwargs)}
field_name: name of the field to add to subclass
field_class: class of the field e.g. ManyToManyField
args: a list of pos args with which to init
field_class
kwargs: a list of keyword args with which to init
field_class
repl_args: either None or a list with the same
length as args that specifies which arguments can be
overridden, and what keyword to use to replace that argument.
repl_kwargs: either None or a dict that specifies
which kwargs can be overridden by subclasses and what keyword to
use for the override.
mandatory: iterable of keywords that
subclasses must replace.
replacements: dict that
specifies the replacements to use in the subclass using the keywords
defined in the repl_args and repl_kwargs in
a parent's Extend.fields values.
redelegate: iterable of field names from
fields in a parent's Extend inner class
that specifies which fields should not be added in this class but its
subclass.
Using the mandatory field in a child class of
Exendable forces grandchildren of to specify replacements
for particular keywords.
Grandchildren may further delegate adding fields to their own children
i.e. the great grandchildren by specifying the field names in their
redelegate field of their inner Extend
class.
For example: :
from django.db import models
class OtherModel(models.Model): pass
class OtherModelRel(models.Model):
parent = models.ForeignKey("TestParent")
other = models.ForeignKey(OtherModel)
class YetAnotherModel(models.Model): pass
class YetAnotherModelRel(models.Model):
child = models.ForeignKey("TestChild")
other = models.ForeignKey(YetAnotherModel)
class TestParent(Extendable):
class Extend:
fields = {
'other': (models.ManyToManyField,
[OtherModel,],
{'through': OtherModelRel},
['other_model',],
{'through': 'other_through'},
),
}
mandatory = [
'other_through',
]
class TestChild(TestParent):
class Extend:
replacements = {
'other_model': YetAnotherModel,
'other_through': YetAnotherModelRel,
}
|
|||
|
__metaclass__ Metaclass for all Extendable models. |
|||
| Meta | |||
| Extend | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from Inherited from |
|||
|
|||
leaf_name = models.CharField(max_length= 100, blank= True, edi
|
|||
module_name = models.CharField(max_length= 100, blank= True, e
|
|||
_default_manager = <expedient.common.extendable.models.Extenda
|
|||
_meta = <Options for Extendable>
|
|||
|
Inherited from |
|||
|
|||
|
Inherited from Inherited from |
|||
|
|||
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
|
|
|||
leaf_name
|
module_name
|
_default_manager
|
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Feb 18 13:09:58 2011 | http://epydoc.sourceforge.net |